- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2018 01:33 AM
Hello All,
I am looking for a way to nicely format an email notification. In particular when a note is added to an incident. At the moment we are just getting the journal entry and printing it on the notification:
I would like to be able to separate out the user who added the notes, the date/time and the note itself so these can be formatted differently.
Can anyone guide me on the best way to achieve this?
Many Thanks
Harry
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2018 02:04 AM
Hi Harry,
I asked this same question a while back, Chuck got back with a solution of using getJournalEntry() and parsing the result with a regex and then doing what you want with the output. I couldn't get that solution working but perhaps you will have more luck with it:
The solution we did get working was done by our implementation partners, it's apparently not best practice as you should use getJournalEntry() but it works! The getUserTime() function is to present the time in the local users time zone, not sure if that's something you'll need but you should be able to modify it to suit your requirements.
(function runMailScript(current, template, email, email_action, event) {
template.print('<p><font size="3" color="#030000" face="arial">');
template.print(gs.getMessage('Your Incident has been updated with the following comments') + ':');
template.print('</font></p>');
var custom_comment = new GlideRecord('sys_journal_field');
custom_comment.addEncodedQuery('element=comments^element_id=' + current.sys_id);
custom_comment.orderByDesc('sys_created_on');
custom_comment.setLimit(3);
custom_comment.query();
while (custom_comment.next()){
var userGR = new GlideRecord('sys_user');
userGR.addQuery('user_name', custom_comment.sys_created_by);
userGR.query();
if(userGR.next()){
var getTZ_time = getUserTime(custom_comment.sys_created_on, userGR.time_zone);
template.print('<div><font size="3" color="#030000" face="arial"><span></span></font><hr></div>');
template.print('<p><strong><font size="3" color="#030000" face="arial">' + getTZ_time + ' ' + userGR.time_zone + ' - ' + userGR.name + '</font></strong></p>');
template.print('<p><font size="3" color="#030000" face="arial"><pre style="background-color:transparent; border: none;">' + custom_comment.value + '</pre></font></p>');
}
}
function getUserTime(date,usertimezone){
var timezone = Packages.java.util.TimeZone.getTimeZone(usertimezone);
var gdt = new GlideDateTime(date);
gdt.setTZ(timezone);
var set1 = gdt.getTZOffset();
gdt.setNumericValue(gdt.getNumericValue() + set1);
return gdt;
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2018 02:04 AM
Hi Harry,
I asked this same question a while back, Chuck got back with a solution of using getJournalEntry() and parsing the result with a regex and then doing what you want with the output. I couldn't get that solution working but perhaps you will have more luck with it:
The solution we did get working was done by our implementation partners, it's apparently not best practice as you should use getJournalEntry() but it works! The getUserTime() function is to present the time in the local users time zone, not sure if that's something you'll need but you should be able to modify it to suit your requirements.
(function runMailScript(current, template, email, email_action, event) {
template.print('<p><font size="3" color="#030000" face="arial">');
template.print(gs.getMessage('Your Incident has been updated with the following comments') + ':');
template.print('</font></p>');
var custom_comment = new GlideRecord('sys_journal_field');
custom_comment.addEncodedQuery('element=comments^element_id=' + current.sys_id);
custom_comment.orderByDesc('sys_created_on');
custom_comment.setLimit(3);
custom_comment.query();
while (custom_comment.next()){
var userGR = new GlideRecord('sys_user');
userGR.addQuery('user_name', custom_comment.sys_created_by);
userGR.query();
if(userGR.next()){
var getTZ_time = getUserTime(custom_comment.sys_created_on, userGR.time_zone);
template.print('<div><font size="3" color="#030000" face="arial"><span></span></font><hr></div>');
template.print('<p><strong><font size="3" color="#030000" face="arial">' + getTZ_time + ' ' + userGR.time_zone + ' - ' + userGR.name + '</font></strong></p>');
template.print('<p><font size="3" color="#030000" face="arial"><pre style="background-color:transparent; border: none;">' + custom_comment.value + '</pre></font></p>');
}
}
function getUserTime(date,usertimezone){
var timezone = Packages.java.util.TimeZone.getTimeZone(usertimezone);
var gdt = new GlideDateTime(date);
gdt.setTZ(timezone);
var set1 = gdt.getTZOffset();
gdt.setNumericValue(gdt.getNumericValue() + set1);
return gdt;
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2018 03:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2018 08:26 AM
David Dubuis - Once again found a solution for me... This time I didn't even need to ask.
Thanks again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2020 02:06 AM
This is all great, but if you have more than one line in your comment, it doesn't get printed in the right font and size.
BR - Thomas