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

Anurag Tripathi
Mega Patron
Mega Patron

For any such activity i always like to use Scheduled jobs.



Create a job that runs everyday (non business hours) and filters the sc_request based on your criteria, cancel all that qualifies. Use setWorkflow(false) to make it quicker and not trigger anything.


-Anurag

Hi Anurag,


Thanks for your reply.


I would create a job for approval table which would be somewhat like this



var gr = new GlideRecord("sysapproval_approver");  


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


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


gr.query();  


if (gr.next())  


{  


gr.state = 'not_required';     // this will not trigger any email since in moving to state no longer required.


gr.update();  


}  



But how will i filter this only for the requests (sc_request)


have you checked the thread that i had shared .


there they created all the script in one script include and call that function in schedule job. please check . hope that will help you


Hi Harshvardhan,



I checked the link you posted but i am unaware how to call the script include in the schedule job.


Could you please check my above schedule job and help mw in that