Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

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

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


-Anurag

Thanks Anurag,



That was perfect.


Now how can we cancel or close incomplete those request


that would be just a similar script where you loop through the sc_request and change its state to cancelled.


-Anurag

Could you please help me with the script