I am calling a mail script from notifications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 11:17 AM
I am calling a mail script from notifications
here is my code

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 12:07 PM
After looking at your code a gain its because you asked it to add the comment for every incident in your incident table.
Assuming this notification is for an incident and you want the last comment and only the last comment then your script just needs to be
template.print(current.comments.getJournalEntry(1));
and nothing else, no loop no GlideRecord queries.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 12:08 PM
Hi @kiran kumar m1 ,
var latestComment;
var gr = new GlideRecord('incident');
gr.query();
while (gr.next()) {
gs.info('inside while');
var sr = new GlideRecord('sys_journal_field');
sr.addQuery('element_id', gr.sys_id);
sr.orderByDesc('sys_created_on');
sr.query();
if (sr.next()) {
latestComment = gr.comments.getJournalEntry(1);
gs.info("line num" + latestComment);
template.print(latestComment +'<br>');
}
}
here the variable declared was scoped so moved it to top and used template.print try the above code and let me know if it works or not ?
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 01:02 PM
@kiran kumar m1 Thanks for marking my answer as helpful. If it helped you in any way please accept the solution so that it will be beneficial to the future readers with the same query.
Thanks,
Swathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 12:35 PM
Hi @kiran kumar m1 ,
What @DrewW is saying is making sense.
Please describe your requirement clearly in detail one more time so that you will get the exact solution.
If it is only comments, you can use ${comments}.
Thanks,
Regards,
Karunakaran.