Writing a background script to change the approver of RITM

amritmishra
Kilo Contributor

The approver of the RITM is no longer with the company, so the user is locked out and the approval of few RITMs is pending for approval. He was the Owner of two Parent Groups in the system. 

I have manually changed the new Group Owner of the mentioned Parent groups. But how can I write a script to change the approver of the pending RITM of that Parent Group with the new Group Owner which I changed just now.

Provided I dont know the exact RITMs pending with the locked out user.

PS. I am new to ServiceNow and I am trying to write code on my own to figure this out. Any help will be great. Thanks in advance!

1 ACCEPTED SOLUTION

Brian Lancaster
Tera Sage

Off the top of my head this should work.  Please test it in a sub prod instance first.

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('approver', 'sys_id');//replace the word sys_id with the sys_id of the user who holds the approvals.
gr.addQuery('state', 'requested'); //Only bring back pending approvals
gr.query();
while (gr.next()){
	gr.approver = 'sys_id of new approver'; //this will need to be the sys_id for the new approver.
	gr.update();
}

View solution in original post

6 REPLIES 6

Can I see your modified script? I don't see why this would cause the workflow to cancel as you are not modifying the workflow just the approval records.

Hi Brian,

 

Thanks for getting back to me on this topic.

 

Here is the script :

var m = new GlideRecord('sysapproval_approver');
m.get('01f3fc62872319506a7f63560cbb353a');
m.approver = '5da8a83cff86ac008fea114e40b9ad40';
m.update();

However, I executed on a dev instance and noticed that the modification was successful and did not corrupt or erase the workflow in place in the RITM.

This specific behavior in our instance is most probably caused by custom business rules or specificities related to our context.

 

So I confirm that your script is working fine.

 

Best regards