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

Shruti
Mega Sage
Mega Sage

Hi

Replace apprRec.setValue('comments','Approval got Autorejected as no action was taken since 7 days');

with apprRec.comments='Approval got Autorejected as no action was taken since 7 days';

Hemanth M1
Giga Sage
Giga Sage

Hi @Harsha34 ,

 

Can you try 

 apprRec.comments= "Approval got Autorejected as no action was taken since 7 days".
 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

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

Thanks anyways, can you please let me know how can i update the same comments in RITM notes?

 

Omkar Mone
Mega Sage

Replace setValue with the below 

 

apprRec.comments = 'Approval got Autorejected as no action was taken since 7 days';