Fix script for changing the CR state

Vasavi O
Tera Contributor

Change request was cancelled but it is still showing up as needing approval in approvers queue. It should not be in the approvers queue . What Can I do to make  disappear those in approvers queue automatically, those  are in "requested" state now , How can I change the state as "no longer required", So that it will be removed from approvers queue, Anyone please share the  fix script for changing the state if you have ?

3 REPLIES 3

Prasad Dhumal
Mega Sage
Mega Sage

Hello Vasavi,

You can execute below script using background script or fix script which will glide the change request table and update the status of any cancelled requests to "No Longer Required". 

var gr = new GlideRecord('change_request');
gr.addQuery('state', 'Requested');  //Set the correct value of state here
gr.addQuery('active', 'false');
gr.addQuery()  //also add more queries if required to narrow down the records
gr.query();
while (gr.next()) {
  gr.state = 'No Longer Required'; //Set the correct value of state here
  gr.update();
}

 Please make sure you are executing this script on 1 record first on dev or test env.

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Looks like you need to update the approval record for a change that was cancelled.

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval', '<sys_id of the change>');  //pass the sys_id of the change
gr.addQuery();
gr.query();
while (gr.next()) {
  gr.state = 'not_required'; 
  gr.update();
}
-Anurag

Mahesh Baraskar
Mega Guru

@Vasavi O   You have to write Before Update business rule on change_request table and the condition in the BR will be State Changes to Cancelled.  In the script, you will need to glide the sys_approval table with the sys_id of the current record.

 

var grApproval = new GlideRecord('sysapproval_approver');
grApproval.addQuery('sysapproval', current.sys_id);
grApproval.addQuery();
grApproval.query();
while (grApproval.next()) {
grApproval.state = 'not_required'; //whichever is the backend value of the state in your change request table
grApproval.update();
}