Script Help for Approvals to Auto Reject in 7 Days

Wendy Peterson
Giga Guru

I have a super bizarre request from our Security Team. If a user changes ROLES they want to send out Tasks to the New Managers to see if they should keep their current access or remove it. If the new Manager doesn't respond within 7 days they want it to be rejected. The approvals are sent from the TASK level. One Request could have possibly 15 approvals for the same manager on it. Can you think of anyway I could do this in the Approval Script? I thought of a Timer but I don't want the whole RITM to cancel since these could go out at different times. etc. You can see what I mean below - I just need to know how i can get each approval individually to reject if it is not approved within 7 days. If it's approved it by passes decomissioning their access.

 

find_real_file.png

 

find_real_file.png

1 ACCEPTED SOLUTION

Mandeep Karan
Tera Guru

here is the script you can use in your scheduled job:

var gr = new GlideRecord('sysapproval_approver');
gr.addEncodedQuery('state=requested^sysapproval.numberLIKEritm^sys_created_on<javascript:gs.beginningOfLast7Days()^sysapproval.ref_sc_req_item.cat_item=<sys id of your catalog item>');
gr.query();
while(gr.next()){
gr.state = 'cancelled';
gr.update();
}

 

//replace the highlighted sys id with your catalog item sys id.

find_real_file.png

 

View solution in original post

9 REPLIES 9

Mandeep Karan
Tera Guru
You can write a scheduled script to cancel the approval if not approved in 7 days. That would be your individual cancellation.

For reference you can use this url: https://community.servicenow.com/community?id=community_question&sys_id=ec064761db1cdbc01dcaf3231f96195c

I thought about that but how would I find just this 1 request and not cancel all other approvals out there. I am sending notifications out by Workflow Activity maybe on that too?

By one request you mean request from one particular catalog item and for others it should not cancel the approval record. Right?