Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need to show the delegate approval comments in Approvers Tab in Change request

Sony Doddapanen
Mega Contributor

Required help @Vasantharajan N @Ankur Bawiskar @Geoffrey2 @Arjun Reddy Yer 

 

As when the change request is approved by Delegate Approver then in the comments section of the Approvers Tab need to show as the "<Time Stamp> Change Request is Approved by Delegate Approver <Approver Name>".

As of now when an Delegate Approver is approving the change request in the comment section it's not showing anything as mentioned below & the Delegate Approved one is showing as false.

SonyDoddapanen_0-1718463996197.png

 

To get the comments tried with Business Rule as mentioned below

Business Rule:

 

SonyDoddapanen_1-1718464239781.png

 

 Script:

 

(function executeRule(current, previous /*null when async*/ ) {
    var user, delegate;
    var gr = new GlideRecord('sys_user');
    if (gr.get('user_name', current.sys_updated_by)) {
        user = gr.name;
    }
    var grd = new GlideRecord('sys_user_delegate');
    grd.addQuery("user", current.approver);
    grd.addQuery("approvals", "true");
    grd.addQuery("starts", "<=", gs.daysAgoEnd(0));
    grd.addQuery("ends", ">=", gs.daysAgoStart(0));
    grd.query();
    while (grd.next()) {
        delegate = grd.delegate.getDisplayValue();
    }
    if (user == delegate) {
        if (current.state.changesTo('approved')) {
            current.comments.setJournalEntry = "The request has been approved by delegate " + user;
        } else if (current.state.changesTo('rejected')) {
            current.comments.setJournalEntry = "The request has been rejected by delegate " + user;
        }
    } else {
        if (current.state.changesTo('approved')) {
            current.comments = "The request has been approved by " + user
        } else if (current.state.changesTo('rejected')) {
            current.comments = "The request has been rejected by " + user;
        }
    }
})(current, previous);
1 REPLY 1

Vasantharajan N
Tera Sage
Tera Sage

@Sony Doddapanen - I don't see any problem with your script. Are you seeing comments as per your need in the actual approval record?


Thanks & Regards,
Vasanth