- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2020 09:03 AM
Hello Experts,
I need to change the state of the Requested Approvals to No Longer Required only for those tickets which are closed complete.
For ex- If a Ritm is closed complete but still its approval is pending with some user who is now inactive then i need to change the state of that approval to No Longer Required using Background script.
There are multiple records.
How to achieve this?
Regards,
Riya
Solved! Go to Solution.
- Labels:
-
Change Management
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2020 09:15 AM
Hi Riya,
You can try using below background scirpt. Check for 1 or 2 records first & then execute it for all. Also, check for messages to get the count for a check.
var app=new GlideRecord('sysapproval_approver');
app.addQuery('state','requested');
app.query();
while(app.next())
{
gs.print('Approval count in requested state '+app.getRowCount());
var chkritm=new GlideRecord('sc_req_item');
chkritm.addQuery('sys_id',app.sysapproval);//gets ritm
chkritm.addQuery('state','3'); //closed complete
chkritm.query();
while(chkritm.next())
{
gs.print('RITM with closed state but approval still in requested state '+chkritm.getRowCount());
app.state='not_required';
app.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2020 09:15 AM
Hi Riya,
You can try using below background scirpt. Check for 1 or 2 records first & then execute it for all. Also, check for messages to get the count for a check.
var app=new GlideRecord('sysapproval_approver');
app.addQuery('state','requested');
app.query();
while(app.next())
{
gs.print('Approval count in requested state '+app.getRowCount());
var chkritm=new GlideRecord('sc_req_item');
chkritm.addQuery('sys_id',app.sysapproval);//gets ritm
chkritm.addQuery('state','3'); //closed complete
chkritm.query();
while(chkritm.next())
{
gs.print('RITM with closed state but approval still in requested state '+chkritm.getRowCount());
app.state='not_required';
app.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2020 09:20 AM
Hi Riya,
You can use the following which will cancel any approvals where the approving task is inactive.
var appr = new GlideRecord('sysapproval_approver');
appr.addQuery('state','requested');
appr.query();
while (appr.next()){
var task = new GlideRecord(appr.sysapproval.sys_class_name);
task.get('sys_id',appr.syapproval.sys_id);
if(task.active == false){
appr.setValue('state','cancelled');
appr.update();
gs.print("Updated Approval for : " + appr.sysapproval.number);
}
}