Help Needed: Notification to Approvers on New RITM Comment

Lisa Goldman
Kilo Sage

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

 

LisaGoldman_0-1750971381035.png

 

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

 

LisaGoldman_1-1750971619197.png

 

LisaGoldman_2-1750971653104.png

 

LisaGoldman_3-1750971714150.png

 

 

Any guidance or suggestions would be greatly appreciated.

Thanks,

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Lisa Goldman 

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.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

J Siva
Tera Sage

Hi @Lisa Goldman 

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Lisa Goldman 

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.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Lisa Goldman 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

 

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);