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

Yeh it's only for this one request not all requests.

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

 

Thanks so much that worked perfectly...

Hii @Mandeep Karan 

 

I just want to know what condition you have applied on table in list view to get this Encoded Query:

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>');

 

Regards,

Imran Ahmad

Hi Imran,

 

Here you go:

find_real_file.png

 

Regards,

Mandeep