Customize email notification in form of color and bold font
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2021 03:35 AM
Hello All,
I want to customize the email notification via Email Script in which all the fields values names will be in bold and in same color. And also I want to display the field vlaues side by side. Like for example Outage Start Date/Time: & Outage End Date/Time: should be in one line.
Number: PRB0042168
Opened: 2021-03-30 15:18:09 IST RCA Report Deliver Date/Time: 2021-03-30 15:18:09 IST
Priority: 4 - Low Location: Dallas
Owned By: Configuration item:
Causing Team: Impacted Team:
Outage Start Date/Time: Outage End Date/Time: Outage Duration:
Vendor Reference: Root Cause Identified Reason:
Short description: test
Event sequence and timeline: test
Short Term Fix: test
Recovery Actions Summary:
RCA Method:
Root Cause Analysis: test
Root Cause and Contributing Factors:
Business Impact:
Long Term Fix:
Other Observations Learnings:
Corrective and Preventive Actions:
And in the below I want to give a link for Click here to view <link> which will redirect the user to view the Problem Record and approve it there itself from the Approvers tab.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2021 12:13 PM
Hello Snow@User,
You will need to embed styling into the HTML you create and print into your email notification from the script. I usually use the method shown in the script below. CSS styles can be applied to the whole HTML div, or individual elements as needed.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// current can be case or task_sla GlideRecord
var className = current.getRecordClassName();
var isTaskSLAType = ( className == 'task_sla' ) ? true : false;
var number = isTaskSLAType ? current.task.number : current.number;
var priority = isTaskSLAType ? current.task.priority.getDisplayValue() : current.priority.getDisplayValue();
var shortDesc = isTaskSLAType ? current.task.short_description : current.short_description; // you can do more of these checks for fields that may not exist in SLA records where you need to traverse to a dot-walked field. These may not be required if you are not reusing the script across record types.
var content = '';
content += '<div style="background-color:black;color:white;padding:20px;font-family:brush script mt">'; //css styling for the whole div
content += '<p>';
content += gs.getMessage( '<strong>Number:</strong> {0}', [number] );
content += '<br />';
content += gs.getMessage( '<strong>Priority</strong>: {0}', [priority] );
content += '<br />';
content += gs.getMessage( '<strong>Outage Start Date/Time: </strong> {0} <strong>Outage End Date/Time:</strong> {1} <strong>Outage Duration:</strong> {2}', [{$start_date}, {$end_date}, {$duration}]);
content += '<br />';
content += gs.getMessage( '<strong>Description: {0}', [shortDesc] );
content += '</p>';
content += '</div>';
template.print( content );
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2021 03:24 AM
Hi Stephen,
The code given by you is bit confusing for me,as I am not that much proficient in scripting.
var className = current.getRecordClassName();
var isTaskSLAType = ( className == 'task_sla' ) ? true : false;
var number = isTaskSLAType ? current.task.number : current.number;
var priority = isTaskSLAType ? current.task.priority.getDisplayValue() : current.priority.getDisplayValue();
var shortDesc = isTaskSLAType ? current.task.short_description : current.short_description; // you can do more of these checks for fields that may not exist in SLA records where you need to traverse to a dot-walked field. These may not be required if you are not reusing the script across record types.
var content = '';
content += '<div style="background-color:black;color:white;padding:20px;font-family:brush script mt">'; //css styling for the whole div
content += '<p>';
content += gs.getMessage( '<strong>Number:</strong> {0}', [number] );
content += '<br />';
content += gs.getMessage( '<strong>Priority</strong>: {0}', [priority] );
content += '<br />';
content += gs.getMessage( '<strong>Outage Start Date/Time: </strong> {0} <strong>Outage End Date/Time:</strong> {1} <strong>Outage Duration:</strong> {2}', [{$start_date}, {$end_date}, {$duration}]);
content += '<br />';
content += gs.getMessage( '<strong>Description: {0}', [shortDesc] );
content += '</p>';
content += '</div>';
template.print( content );
Here you have given for Task SLA Record. But in my case I want to do it for problem record. And what about the fieds names where to embed it within the script?
Like for example
content += gs.getMessage( '<strong>Priority</strong>: {0}', [priority] );
In this the field name is priority correct me I am not wrong?
Please kindly help me out here in brief for my better understanding.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2021 10:30 AM
Hello -
The section referring to taskSla could be eliminated. It is there for potential reuse of a script. It checks the class of the record and if it is an SLA record, it dotwalks to the target task to get the values. You are correct on the priority field above. It is labeled and then calls the value from the record. Anywhere that you see '<strong>XYZ</strong>' is where we are setting the field name and making it bold. For simplification, I've updated the script snippet I provided before to only use the 'current.FieldName' nomenclature. Anywhere you see 'current.xyz', that is where we are pulling the value of a field from the record and placing it into the email.
Note that I don't know the actual name of your outage date fields as those are not in the baseline instance. You will need to replace my placeholder values with the correct field name. This is not the label, but the actual name. You can see the actual name of the field when you right click on the field label on the form.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var content = '';
content += '<div style="background-color:black;color:white;padding:20px;font-family:brush script mt">'; //css styling for the whole div
content += '<p>';
content += gs.getMessage( '<strong>Number:</strong> ' + current.number + '<br />');
content += gs.getMessage( '<strong>Priority</strong>: ' + current.priority + '<br />');
content += gs.getMessage( '<strong>Outage Start Date/Time: </strong>' + current.u_outage_start_date + '<strong> Outage End Date/Time:</strong> ' + current.u_outage_end_date + ' <strong> Outage Duration:</strong> ' + current.u_outage_duration + '<br />');
content += gs.getMessage( '<strong>Description: ' + current.short_description + '<br />');
content += '</p>';
content += '</div>';
template.print( content );
})(current, template, email, email_action, event);