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-05-2020 04:19 AM
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
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2020 06:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2020 09:27 PM
Hi Sudhachandan,
You need to create scheduled job under System Definition -> Scheduled Jobs
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
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2020 02:27 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2020 11:20 PM
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
Mohit Kaushik
ServiceNow MVP (2023-2025)