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

Line number 2 is checking that it is for RITM and it not updated with last 15 days.

app.addEncodedQuery('sys_updated_on<=javascript:gs.beginningOfLastMinute()^sysapprovalSTARTSWITHRITM);

 

In this query just add one more condition so that it will not check already rejected approvals:

app.addEncodedQuery('sys_updated_on<=javascript:gs.beginningOfLastMinute()^sysapprovalSTARTSWITHRITM^state!=rejected');

 

Thanks,

Mohit Kaushik

 

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Hello Mohith,

 

Below is my query:

 

It is written on sysapproval_group table:

 

Please find my code attached.

 

It is not changing the approval value to rejected.

 

 

Hi Sudhachandan,

You need to create scheduled job under System Definition -> Scheduled Jobs

find_real_file.png

Business rule will not run automatically everyday. A schedule job only will fulfill that purpose.

Put your script in there and then try with executing now and see if the changes are happening.

You can put some gs.log("any text to check in logs that your job ran").

 

Thanks,

Mohit kaushik

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Thanks Mohith,

 

Mohith, I am trying to find a query to link RITM table and sysapprover_group table.

 

I am using this below query:

var app = new GlideRecord("sysapproval_group");
app.addQuery('parent', 'ritm.number');

 

Could you please correct me if this is wrong?

I am really struck here.

 

Hi,

To link  sysapproval_group table with RITM you can filter like this.

var app = new GlideRecord("sysapproval_group");
app.addQuery('parent', 'sys_id of RITM');

Because parent is a reference field and not string. So you can not compare with number.

or 

If you want to compare with number only then you can do like this.

app.addQuery('parent.getDisplayValue()', ' Number or RITM');

 

 

Thanks,

Mohit Kaushik

 

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)