Email Notification formatting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2013 08:48 AM
Hi,
Has anyone managed to change the look of the system generated email notification templates, I'm trying to make them look a little more corporate but can't figure it out. I've picked some script up from somewhere but can't figure out how to get it to do what I want and it doesn't want to play fair.
What I am trying to do is:
1). Minimise the number of journal entries included in my customer visible email to 2.
2). Change the font of the entire email notification to Calibri
3). Make the most recent comment more visible in the email by making it a different colour, In this case light blue.
Here is the script I am using in the email template being used:
Incident: ${URI_REF} has been updated Please see latest comments below
Incident short description: ${short_description}.
setFontForComments();
function setFontForComments() {
var sid = current.sys_id;
var incidents = new GlideRecord('incident');
incidents.addQuery('sys_id','=',sid);
incidents.query();
while(incidents.next()) {
var comments = incidents.comments.getDisplayValue();
comments = comments.replace(/(\d+-\d+-\d+.*?)(\(Additional comments\))/gim,"$1 ");
comments = "";
comments = comments.replace(/(\
))/gim,"$1");
//comments = "" + comments + "";
template.print(comments);
}
}
Priority: ${priority}
Assignment group: ${assignment_group}
attachLinks();
function attachLinks() {
//Check for any attachments and add attachment links if they exist
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id',current.sys_id);
gr.query();
if(gr.hasNext()){
template.print("Attachments: \n");
while (gr.next()) {
var attachLink = '
}
template.print("");
}
}
Description: ${description}
Be kind this is my first go at this sort of stuf...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2013 08:51 AM
I've added a .txt file of the script as it didn't quite transfer as I expected it to.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2013 12:50 PM
Here's how you could get the last two comments only and color the first one blue:
< mail_script >
printComments();
function printComments() {
var cmtStr = current.comments.getJournalEntry(2); // gets the last 2 comments from the journal, seperated by \n\n
cmtStr.replace(/(\d+-\d+-\d+.*?)(\(Additional comments \))/gim,"< hr />< strong>$1< /strong> < !--< sup>$2< \/sup>-->"); //this regular expression sometimes didn't work in my testing
var cmtArray = cmtStr.split("\n\n"); // splits on \n\n
template.print("< font color='#0099D8' face='Calibri'>" + cmtArray[0] + "\n\n< /font>"); // prints the first comment in blue
template.print("< font face='Calibri'>" + cmtArray[1] + "\n\n< /font>"); //prints the second comment
}
< /mail_script >
I hope that helps!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2013 06:40 AM
Hi Neil
We setup our notifications to send the last comment added to do this you need to change the comments added event which is in each events buisness rule and some text in the actual email.
Details can be found here
http://wiki.servicenow.com/index.php?title=Using_Journal_Fields
We modified the incident events business rule as follows:
if (current.operation() != 'insert' && current.comments.changes()) {
var cmt = current.comments.getJournalEntry(1);
gs.eventQueue("incident.commented", current, gs.getUserID(),cmt);
}
This sends the last comment to send 2 just increment current.comments.getJournalEntry(1); by 1
The email notification needs the below paraemeter to pick up the comment.
comments:
${event.parm2}
Hope that helps
Neil.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2013 06:52 AM
It looks like its working, I've taken the first suggestion of the template script as we have several business units and until they tell me that they only want to see the latest comments I can't do the global change.
Many thanks for your help and suggestions. It's been very helpful.