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 10:38 PM
Hi,
I tried a BR on approval table and checked for the conditions when the state is rejected and approval is for RITM. After that i glided record for RITM and it is making the state to close complete. You can change that as per your requirement.
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 11:06 PM
Hello Mohith,
I understood.
However my scenario is this:
If the RITM is not approved till 15 days , then it is auto rejected.
For that purpose , I have written one schedule job, which runs every 1 hour and checks if the RITM is not approved within 15 days.
If RITM not approved, then approval is auto-rejected
Once the auto rejection is done, the state of RITM should change.
Can this be achieved by using the business rule provided by you.
If yes, then how can I link this business rule to my schedule job?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2020 11:29 PM
Hi Sudhachandan,
The BR which Mohit has given.. you just need to modify the script in Action after the glide query where you can find when the RITM first opened with the current date, if the difference more than 15 days then below scripts which Mohit has given should be executed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2020 11:49 PM
Hello Rick,
Thank you.
I am not able to figure it out.
Could you please give me an demo query for the same and where to write it.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2020 11:54 PM
Hi Sudhachandan,
you can modify the Mohit BR scripts such as below
var currentDate = new GlideDateTime();
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('number', current.sysapproval.getDisplayValue());
ritm.query();
if (ritm.next()) {
openedTime = item.opened_at;
var diffDays = gs.dateDiff(currentDate, openedTime, false);
if (diffDays > 15) {
current.approval = 'rejected value';
current.work_notes = 'rejecting';
current.update();
ritm.state = 3;
ritm.update();
}
}