Cancel Requests which are pending approval for more than 3 months

Aakash Shah4
Tera Guru

Hi Guys,

I have a requirement to cancel all the requests which are pending approval for more than 3 months without sending email notifications.

The email notifications are applied on the sc_request table for both, request approved or rejected.

Any help is appreciated.

1 ACCEPTED SOLUTION

Aakash Shah4
Tera Guru

Thanks Guys for you help, i found the solution.



Created a Schedule Job :



var gr = new GlideRecord("sysapproval_approver");


gr.addQuery('sysapproval.sys_class_name','sc_request');


gr.addQuery('state','requested');


gr.addQuery('sys_created_on','<',gs.daysAgo(90));


gr.query();


while (gr.next()) {


  gr.state = 'not_required';


  cancelRequest(gr.sysapproval.number);


  gr.update();


}



function commentParent(reqNum) {


  var scReq = new GlideRecord("sc_request");  


              scReq.addQuery('number',reqNum);  


              scReq.query();  


              if(scReq.next()){                          


                      scReq.state = 4;  


                      scReq.stage = 'closed_incomplete';  


                      scReq.request_state = 'closed_cancelled';  


                      scReq.update();


}


View solution in original post

11 REPLIES 11

Chuck Tomasi
Tera Patron

I invite you to take a look at a scriptless solution I built for situations exactly like this.



Scriptless scheduled jobs


Aakash Shah4
Tera Guru

Thanks Guys for you help, i found the solution.



Created a Schedule Job :



var gr = new GlideRecord("sysapproval_approver");


gr.addQuery('sysapproval.sys_class_name','sc_request');


gr.addQuery('state','requested');


gr.addQuery('sys_created_on','<',gs.daysAgo(90));


gr.query();


while (gr.next()) {


  gr.state = 'not_required';


  cancelRequest(gr.sysapproval.number);


  gr.update();


}



function commentParent(reqNum) {


  var scReq = new GlideRecord("sc_request");  


              scReq.addQuery('number',reqNum);  


              scReq.query();  


              if(scReq.next()){                          


                      scReq.state = 4;  


                      scReq.stage = 'closed_incomplete';  


                      scReq.request_state = 'closed_cancelled';  


                      scReq.update();


}