How to change state of RITM when Approval is rejected automatically by a Scheduled Job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2020 09:36 PM
Here is the scenario:
When approval is rejected by the approver, then state of RITM changes to 'Cancelled'. This is performed by a workflow and is working perfectly.
In case if the approver takes no action for 15 days, then RITM is auto rejected. Upon Auto rejection we want to set the 'State' as 'Closed'.
I have written 1 schedule job for the same(screenshot attached).
But it is not working.
Any help will be appreciated.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2020 09:51 PM
Hi Sudhachandan,
I had a quick look at your screenshot and the logic seems like it could use some work -
First, for every single approval you have queried you are setting the approval to Rejected - this means you don't need the "if (app.approval == 'rejected')" query. Also, it seems you may be missing a closing bracket (unless it's out of the screenshot).
It's also good practise to not use "gr" as a variable name as it's frequently used in the system and can cause conflicts.
As an alternative option, I have created a flow which is triggered on creation of a sysapproval_approver record and waits, then uses "Update Record" to change State and Stage on the Approval For record. This may be another option?
Thanks,
Andrew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2020 10:01 PM
Hi Sudhachandan,
You don't need line number 10 and 13, if you want to check the approval state is rejected then you can directly start from line 14 with your if condition.
Now you need to find the correct RITM so for that you need to filter it out like this
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('number',app.sysapproval.getDisplayValue()); sysapproval field is reference field which refers to task table. So we will take display value and compare it with number.
ritm.query();
if(ritm.next())
{
rest of the code
}
Please mark this answer correct if it resolved the query and mark it helpful too if it helped you at all.
Thanks,
Mohit Kaushik
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2020 10:15 PM
Hello Mohith,
Thank you for the response.
However the state value is not changing, even after the approval is rejected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2020 10:24 PM
How are you handling the auto reject for approval?
Is there a workflow which is making it and then changing the state of RITM?
Regards,
Mohit
Mohit Kaushik
ServiceNow MVP (2023-2025)