How can I format a field variable in email notifications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2022 09:06 AM
Hello -
This is the first time I've ever been asked for this when developing these email notifications, but thought it was an odd request and not sure if it's feasible.
But when you are creating an email notification you can select from a list of fields/variables...
as seen above, the additional comments is the exact variable/field I am speaking of. Now, is there a way to edit how that data comes over onto the email notification? Meaning, can I adjust the font style and size in how it appears?
Make sense?
Let the replies roll!
Thank you.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2022 09:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2022 10:00 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2022 02:49 AM
Ah! You can't format comments by the looks of it. You can do it by a quick script though.
Create a new mail script, call it what you like, then use this code (you might want to adjust the span style though as this is my obnoxious black and orange formatting)
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var comments = current.comments.getJournalEntry(-1);
//split by new line
var commentsArray = comments.split('\n\n');
var formattedComments = '';
for (var i = 0; i<commentsArray.length; i++){
//because this now means the comments are a string, they don't keep new lines between the summary and the comment. So, break these.
var splitComment = commentsArray[i].split('\n');
formattedComments+= '<p><span style="font-size: 18pt; color: #ff6600; background-color: #000000;">'+splitComment[0]+'<br>'+splitComment[1]+'</span></p><br>';
}
template.print(formattedComments);
})(current, template, email, email_action, event);
You can then call the script within the body of the notification as normal - ${mail_script:scriptName}. The end result looks like this:
You can obviously adjust the html further to get a nicer decoration//the lines between the comments if you wish.