'Comments' in email notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2018 06:14 AM
Hi,
I have a requirement to show 'comments' in the request rejection email notification. At the moment the script is not working. It just shows blank space for 'Comments'. Below is my notification, template and the script. Could someone help me where it's going wrong.
Thank you
Notification:
Template:
email script:
var comment = new GlideRecord("sysapproval_approver");
comment.addQuery("sysapproval", current.sys_id);
comment.query();
while (comment.next()) {
var comments = rec.comments.getJournalEntry(1);
template.print("<b>Comments:</b>" + comments + "\n");
template.print("<b>Comments:</b>" + comments.substring(comments.indexOf("\n")+1) + "\n");
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2018 07:38 AM
It's because you don't have access to the current object from a background script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2018 07:04 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2018 07:40 AM
It's because you had the template print statement in twice, just simplify it like this:
var approval = new GlideRecord("sysapproval_approver");
approval.addQuery("sysapproval", current.sys_id).addOrCondition("document_id", current.sys_id);
approval.addQuery("state", "rejected");
approval.query();
while (approval.next()) {
var comments = approval.comments.getJournalEntry(1);
template.print(comments);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2018 07:45 AM
Brad,
It looks fine except that the date and the name are still getting displayed. Is there a way to hide?
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2018 07:50 AM
You'd have to parse that out using regex. You might try something like the following:
var comments = approval.comments.getJournalEntry(1);
var dateRE = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.*\n/;
template.print(comments.replace(dateRE, ''));