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.

Comments not getting updated in approval table while autorejecting approvals in approval table

Harsha34
Tera Expert

Hi @SN_Learn 

I am trying to update approval comments with below script but it is not running, though the state got updated , but there is some issue in comments, I guess it is a journal field but can you please suggest how to find the backend name? I searched in XML but it shows comments.

 

function autoCloseRITM() {
   var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', '13563627482894989294992'); /// testing this for a single RITM
//gr.addEncodedQuery("sys_created_onRELATIVELT@dayofweek@ago@7^approval=requested^active=true"); //This will check for RITM not approved in 7 days from the created date
gr.query();
while (gr.next()) {

    var apprRec = new GlideRecord('sysapproval_approver');
    apprRec.addQuery('sysapproval',gr.sys_id); //RITM sysID
    apprRec.query();
    while (apprRec.next()) {
        if (apprRec.state != 'approved') {
            apprRec.setValue('state', 'rejected');
            apprRec.setValue('comments','Approval got Autorejected as no action was taken since 7 days');
            apprRec.update();
        }
    }
}
}
 
 
           This is not running--> apprRec.setValue('comments','Approval got Autorejected as no action was taken since 7 days');
 
Thanks
1 ACCEPTED SOLUTION

Extending the code to glide RITM in your while(appRec.next())

 

var ritmGr = new GlideRecord('sc_req_item');
    if (ritmGr.get(apprRec.sysapproval)) {
        ritmGr.comments = 'Approval got Autorejected as no action was taken since 7 days'; 
        ritmGr.update();
    }

 

 

View solution in original post

8 REPLIES 8

My bad, I didn't see that I am setting up a value:).

 

Can you please let me know how can I update the same comment in RITM notes?

I am doing it through schedule job.

Thanks

Extending the code to glide RITM in your while(appRec.next())

 

var ritmGr = new GlideRecord('sc_req_item');
    if (ritmGr.get(apprRec.sysapproval)) {
        ritmGr.comments = 'Approval got Autorejected as no action was taken since 7 days'; 
        ritmGr.update();
    }

 

 

I used this script in while loop after closing of if loop. It worked.

Thanks a lot!

That's exactly where you had to do it. Glad to know it helped. 🙂