Skip to content

Commit cce3e46

Browse files
authored
Print record detailsin email body (#1304)
* Create readme.md Added the details how the script is being executed and purpose of the email script * Update readme.md Added detailed description of how the script is being executed and purpose of the email script * Create print_record_details_to_body.js Email script to print the details of current record, it can be called in any of the email notification
1 parent 99a67bc commit cce3e46

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Start the HTML container with gray color and Helvetica font
2+
template.print('<div style="color: #808080; font-family: helvetica;">');
3+
4+
// Display the Short Description label in bold and larger font
5+
template.print('<font size="4"><strong>Short Description: </strong></font>');
6+
7+
// Display the actual short description from the current record in a smaller font
8+
template.print('<font size="3">' + gs.getMessage(current.short_description).replace(/(\r\n|\n|\r)/g, '') + '</font>');
9+
template.print('<br />\n'); // Add a line break after the short description
10+
11+
// Display the Description label in bold and larger font
12+
template.print('<font size="4"><strong>' + gs.getMessage('Description') + ':</strong></font>');
13+
14+
// Display the actual description from the current record, preserving line breaks
15+
template.print('<font size="3" style="white-space: pre-line;">' + gs.getMessage(current.description) + '</font>');
16+
template.print('<br />\n'); // Add a line break after the description
17+
18+
// Display the Comments label in bold and larger font
19+
template.print('<font size="4"><strong>' + gs.getMessage('Comments') + ':</strong></font><br />');
20+
21+
// Display the actual comments from the current record in a smaller font
22+
template.print('<font size="3">' + gs.getMessage('${current.comments}') + '</font>');
23+
24+
// Close the HTML container
25+
template.print('</div>');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
1. Overview
2+
This mail script is designed for use in ServiceNow notifications. It dynamically generates an HTML structure that displays key record details (Short Description, Description, and Comments) in a visually appealing format. The script can be used in any ServiceNow notification to provide recipients with a clear, styled summary of the record's information.
3+
4+
2. How It Works
5+
Key Fields:
6+
7+
Short Description: Retrieves and displays the record’s short description.
8+
Description: Retrieves the full description of the record, preserving white spaces and line breaks.
9+
Comments: Retrieves the comments added to the record.
10+
11+
The content is wrapped inside a <div> container, with styling applied using the HTML <font> tag to set the font size, bold text, and color.
12+
The use of gs.getMessage() allows for internationalization, ensuring that the script works well in multi-language environments.
13+
3. Steps to Implement
14+
Create a Notification:
15+
16+
Navigate to System Notification > Email > Notifications in ServiceNow.
17+
Create a new notification or edit an existing one based on your requirements.
18+
Insert the Mail Script:
19+
20+
In the notification, go to the Message tab.
21+
Use the Mail Script type to call the script in your notification message.
22+
The script will dynamically pull the details from the current record (such as incident or task).
23+
Adjust the Script:
24+
25+
If needed, modify the script to display other fields or refine the content (e.g., fetching only specific journal comments).
26+
You can add additional fields like Priority, Assigned to, or custom fields using a similar method.
27+
4. Testing the Script
28+
Send a Test Email:
29+
30+
After configuring the notification, trigger the event to send a test email.
31+
Ensure the email is formatted correctly and that the Short Description, Description, and Comments are displayed as expected.
32+
Positive Test Case:
33+
34+
Create or update a record that matches the notification conditions.
35+
Verify that the email contains the correct record details in the styled format.
36+
Negative Test Case:
37+
38+
Ensure that if no comments or description are available, the script does not throw errors but handles the empty fields gracefully.
39+
5. Benefits
40+
Improved Formatting: The use of HTML ensures that the notification looks professional, with clear headings and properly formatted text.
41+
Dynamic Content: The script automatically pulls data from the record, reducing manual intervention and the risk of errors.
42+
Internationalization: The use of gs.getMessage() allows for easy translation and localization of the content, making the script adaptable to global implementations.
43+
Reusability: This script can be reused across multiple notifications and customized easily to include additional fields or change the format.
44+
This approach enhances the quality of ServiceNow notifications, providing clear and well-structured information to end users.

0 commit comments

Comments
 (0)