How to change state of RITM when Approval is rejected automatically by a Scheduled Job

Sudhachandan
Kilo Explorer

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.

21 REPLIES 21

Danish6
Giga Expert

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.

 

Danish6
Giga Expert

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();
}
}