- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2022 09:55 AM
I am looking to Auto-Reject any RITM that has an approval pending after 7 days. I think this would do it, but I have not been actively working in SNOW for 4 years.
Would this script in Scheduled Jobs do it?
___________________________________________________
gs.log("Job run::aged approval Rejected:" + new GlideDateTime());
var gr = new GlideRecord('sysapproval_approver');
gr.addEncodedQuery('state=requested^sysapproval.numberSTARTSWITHRITM');
gr.query();
while (gr.next()) {
var gdStart = new GlideDateTime(gr.sys_created_on);
var g1 = new GlideDateTime();
var date_diff = GlideDateTime.subtract(gdStart, g1);
var nDays = parseInt(date_diff.getNumericValue()/86400000);
gs.info('Approval for->' + gr.sysapproval.number + ' ' + nDays);
if (nDays > 7) {
gs.eventQueue('Approval.reminder', gr);
gr.state = 'rejected';
gr.setWorkflow(false);
gr.update();
}
}
gs.log("Job complete::aged approval Rejected:" + new GlideDateTime());
_________________________________________________________
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2022 11:50 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2022 11:11 AM
Isn't your RITM having an associated workflow?
If so, you can put a timer of 7 days and after that check the state: if the RITM is not approved, then reject the approval (set approval field to "rejected").
This will be more accurate compared with the usage of the scheduled job.
Another option is to create an event as soon as the RITM is created. That event will be triggered in 7 days. Associated with the event you can have a script action. That script action can set the RITM approval to "Rejected".
Additionally, in your solution you are using the set Workflow(false) statement: be aware that notifications and business rules will not run when using the setWorkflow(false).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2022 11:22 AM
I got pulled in at the behest of my company because there were issues with the ITSM deployment done by an outside Agency. For some reason they decided to delete all flows, subflows, workflows, etc... were delted and they made a very simplified system. One example is all REQ are auto-approved. Notifications were gutted as well. I say this because I am in the process of rebuilding, in a past life I was initimately involved in the deployment of SNOW to a very large org and working on it for several years. But I am looking for bandaids to put in as I work through things. So I do agree the final state is as you suggest.
My need is just immediate and interim, so I wanted to do a scheduled job.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2022 11:50 AM