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

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();
}

MC20
Tera Contributor

How can I modify this to update the approvers for 108 RITMs and all of the managers are different for those RITMs. Basically what I want to do is to change the approver to the users manager. But I have 108 RITMs to go through.

If I'm understanding correctly something like this should work. Note please test this in a dev environment 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()){
        //lookup RITM to determin manager of requested for.
	var ritm = new GlideRecord('sc_req_item');
	ritm.addQuery('sys_id', gr.sysapproval);
	ritm.query();
	if (ritm.next()){
		gr.approver = ritm.request.requested_for.manager; //get requested for manager
		gr.update();
	}
}

midjoule
Kilo Sage

Hello,

I've executed the proposed script above to modify the approver of few RITMs, but when the new approver approves the RITM then the workflow is killed (not possible to "Show workflow" on the RITM) and the catalog tasks have disappeared. 

I tried to "Setworkflow(false)" before updating, but it doesn't help.

This might be a new feature of ServiceNow, which reinforces security and make sure the expected people validate the RITM.

Any comment ?

Best regards