The CreatorCon Call for Content is officially open! Get started here.

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

Arjun Reddy Yer
Tera Guru

Required help @Vasantharajan N @Ankur Bawiskar @Geoffrey2 @Sony Doddapanen 

 

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.

ArjunReddyYer_0-1718467132452.png

 

To get the comments tried with Business Rule as mentioned below

Business Rule:

 

ArjunReddyYer_1-1718467132404.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 ACCEPTED SOLUTION

Tabassum22
Tera Guru

Hi @Arjun Reddy Yer,

 

You may try using current.update() after assigning value to the comments.

 

here is a link which you can refer: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0715782#:~:text=Description,t....

 

You may utilize the below code for the same

current.setWorkflow(false);
current.update();
current.setWorkflow(true);

 

Please mark it helpful and try to give it a thumbs up if the above helps. Please accept the solution.

 

Thanks & Regards

Tabassum Sultana

View solution in original post

1 REPLY 1

Tabassum22
Tera Guru

Hi @Arjun Reddy Yer,

 

You may try using current.update() after assigning value to the comments.

 

here is a link which you can refer: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0715782#:~:text=Description,t....

 

You may utilize the below code for the same

current.setWorkflow(false);
current.update();
current.setWorkflow(true);

 

Please mark it helpful and try to give it a thumbs up if the above helps. Please accept the solution.

 

Thanks & Regards

Tabassum Sultana