- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2025 02:02 PM
Hi,
I need your help with a notification issue. We have a catalog item with multiple approvers. When a new comment is
added to the associated RITM, we want to notify all approvers with the latest comment.
I’ve attempted to implement this, but it’s not working as expected. Here’s what I’ve done so far:
EVENT Name: ritm.new.comment
BUSINESS RULE:
- Run after update
- Script
(function executeRule(current, previous /*null when async*/ ) {
var lastComments = current.comments.getJournalEntry(1);
var arr = [];
var sysApprovalGR = new GlideRecord("sysapproval_approver");
sysApprovalGR.addEncodedQuery("sysapproval=" + current.getUniqueValue();
sysApprovalGR.query();
while (sysApprovalGR.next()) {
arr.push(sysApprovalGR.getValue("approver"));
}
gs.eventQueue('ritm.new.comment', current, arr.toString(), current.getDisplayValue('approver'));
})(current, previous);
NOTIFICATION: Tigger on sc_req_item Table
Any guidance or suggestions would be greatly appreciated.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2025 08:41 PM
try these changes
1) update business rule logic to send latest comments as event parm2 and closing bracket is updated in encodedQuery
2) in email body use this to print the latest comments (you are not sending it so approvers won't know the comments)
(function executeRule(current, previous /*null when async*/ ) {
var lastComments = current.comments.getJournalEntry(1);
var arr = [];
var sysApprovalGR = new GlideRecord("sysapproval_approver");
sysApprovalGR.addEncodedQuery("sysapproval=" + current.getUniqueValue());
sysApprovalGR.query();
while (sysApprovalGR.next()) {
arr.push(sysApprovalGR.getValue("approver"));
}
gs.eventQueue('ritm.new.comment', current, arr.toString(), lastComments);
})(current, previous);
In Email body use this
Latest comments are: ${event.parm2}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2025 08:30 PM
There's a syntax error in your BR script on line 5 — you forgot to close the parenthesis.
Try the revised script below; it should work.
(function executeRule(current, previous /*null when async*/ ) {
var lastComments = current.comments.getJournalEntry(1);
var arr = [];
var sysApprovalGR = new GlideRecord("sysapproval_approver");
sysApprovalGR.addEncodedQuery("sysapproval=" + current.getUniqueValue());
sysApprovalGR.query();
while (sysApprovalGR.next()) {
arr.push(sysApprovalGR.getValue("approver").toString());
}
gs.eventQueue('ritm.new.comment', current, arr.toString(), current.getDisplayValue('approver'));
})(current, previous);
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2025 08:41 PM
try these changes
1) update business rule logic to send latest comments as event parm2 and closing bracket is updated in encodedQuery
2) in email body use this to print the latest comments (you are not sending it so approvers won't know the comments)
(function executeRule(current, previous /*null when async*/ ) {
var lastComments = current.comments.getJournalEntry(1);
var arr = [];
var sysApprovalGR = new GlideRecord("sysapproval_approver");
sysApprovalGR.addEncodedQuery("sysapproval=" + current.getUniqueValue());
sysApprovalGR.query();
while (sysApprovalGR.next()) {
arr.push(sysApprovalGR.getValue("approver"));
}
gs.eventQueue('ritm.new.comment', current, arr.toString(), lastComments);
})(current, previous);
In Email body use this
Latest comments are: ${event.parm2}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2025 09:52 PM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2025 08:30 AM
This is for my learning purposes. I also added ${event.parm1} in the email body to see if the approvers' names would display. However, it is currently showing their sys_id values instead.
Could you please provide guidance on how to modify the code so that it displays the approvers' names instead of their sys_ids? Thank you so much.
(function executeRule(current, previous /*null when async*/ ) {
var lastComments = current.comments.getJournalEntry(1);
var arr = [];
var sysApprovalGR = new GlideRecord("sysapproval_approver");
sysApprovalGR.addEncodedQuery("sysapproval=" + current.getUniqueValue());
sysApprovalGR.query();
while (sysApprovalGR.next()) {
//arr.push(sysApprovalGR.getValue("approver"));
arr.push(sysApprovalGr.approver.getDisplayValue()); // Get the user's display name
}
gs.eventQueue('ritm.new.comment', current, arr.toString(), lastComments);
})(current, previous);