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 11:28 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:55 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();
}
}