- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
For on-prem Xanadu:
I have a requirement to include the latest public comment (comments:1 or current.comments) into the email notifications that get sent out. However, no matter what variation I use of the getJournalEntry(), I am getting the date, name of the commenter, (Additional Comments), <comment>. There was a line-break hint (\n) but SN doesn't like any variation of JS, HTML, or UNICODE I have found for the line break. I believe this line break tip was to extract the Comment from the entire journal entry.
I'm getting better at scripting in SN but any help would be much appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @nickde
In ServiceNow on-prem (Xanadu), the comments field is a journal field, so by default methods like getJournalEntry() return the full formatted entry:
2025-09-20 10:12:34 - John Doe (Additional comments)
This is the actual comment
That’s why you’re always seeing timestamp, user, and label bundled with the comment itself.
The problem
You only want the latest comment text itself (not the metadata), and when you try to split it, you run into issues with line breaks.
Working approach
You can pull only the latest raw comment like this:
(function execute(current) {
var latestComment = "";
var gr = new GlideRecord('sys_journal_field');
gr.addQuery('element_id', current.sys_id); // record you’re on
gr.addQuery('element', 'comments'); // journal field
gr.orderByDesc('sys_created_on'); // newest first
gr.setLimit(1);
gr.query();
if (gr.next()) {
latestComment = gr.value.toString();
}
// make it safe for email (convert newlines to <br/>)
latestComment = latestComment.replace(/\r\n|\n/g, '<br/>');
template.print(latestComment);
})(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @nickde
In ServiceNow on-prem (Xanadu), the comments field is a journal field, so by default methods like getJournalEntry() return the full formatted entry:
2025-09-20 10:12:34 - John Doe (Additional comments)
This is the actual comment
That’s why you’re always seeing timestamp, user, and label bundled with the comment itself.
The problem
You only want the latest comment text itself (not the metadata), and when you try to split it, you run into issues with line breaks.
Working approach
You can pull only the latest raw comment like this:
(function execute(current) {
var latestComment = "";
var gr = new GlideRecord('sys_journal_field');
gr.addQuery('element_id', current.sys_id); // record you’re on
gr.addQuery('element', 'comments'); // journal field
gr.orderByDesc('sys_created_on'); // newest first
gr.setLimit(1);
gr.query();
if (gr.next()) {
latestComment = gr.value.toString();
}
// make it safe for email (convert newlines to <br/>)
latestComment = latestComment.replace(/\r\n|\n/g, '<br/>');
template.print(latestComment);
})(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Thank you Rafael, that's exactly what I needed!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Rafael, any idea why this isn't working in the subject line? It's just regurgitating my ${mail_script:Current_Comment} instead of calling the data. The same thing works perfectly in the body of the email.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @nickde
In ServiceNow, the subject line of an email notification doesn’t process mail scripts (${mail_script:...}), it only evaluates simple variables (${var}) and dot-walked fields from the record.
That’s why in your body it works fine (the mail script is executed), but in the subject it’s being treated as a literal string.
Why
- Body → Supports mail scripts, Jelly, etc.
- Subject → Limited parser → only evaluates record fields and notification variables, not full mail scripts.