Fix script for changing the CR state
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2023 06:09 AM
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2023 08:35 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2023 09:20 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2023 10:19 AM
@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();
}