
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2017 03:20 AM
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.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2017 11:06 PM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2017 03:27 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2017 03:43 AM
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)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2017 04:00 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-12-2017 04:07 AM
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