Post a comment on the RITM Approvers Tab when approval is created on the RITM

Ken61
Giga Guru

The requirement is to populate comment on the approver tab when An approval has been added before the SCTASK created.

"My business rule on "sc_req_item" table, shown below, is not populating the approver tab for all users. Only a few users are being populated, and it is also posting multiple comments on a single record."

 

How can I modify the script to populate comments once for all the approvers

 

Ken61_0-1750186844285.png

 

Ken61_1-1750187050171.png

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var approval = new GlideRecord('sysapproval_approver');
    approval.addQuery('sysapproval', current.sys_id); // document_id on approval refers to the RITM
    approval.query();
    gs.info("Approval count" + approval.getRowCount());
    if (approval.next()) {
        // Copy RITM description to approval comment field

        approval.comments = "Testing";

        approval.update();
    }

})(current, previous);

 

2 REPLIES 2

sahiltelani
Tera Contributor

It's always considered as best practice in ServiceNow to use "setLimit(1)" if we are using "If" statement after the query. Try limiting. I hope too don't have anything to do with the count of the number of approvals? 

Ashwani
Tera Contributor

As per your requirement, you can rather try writing an after insert Business Rule on sys_approval table.

In the BR, you can check if the related request item does not have sc_task created, then add a comment on your approval record.