- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2025 11:26 AM
Hi Everyone,
I have Jira where I have to do a scheduled job to cancel requested items stuck in approval for more than 30 days.
I have executed the following script in background script it is running (the given ritm is getting rejected). When I executed in Scheduled job its not even getting executed.
The script I used in BG script
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addEncodedQuery('cat_item=fcb5900a1bdc82104db699f2b24bcb75^sys_created_on<=javascript:gs.beginningOfLast30Days()^stage!=complete^approval!=approved^ORapproval=NULL');
ritmGR.query();
while(ritmGR.next()){
ritmGR.setValue('state','4');
ritmGR.setValue('close_notes','Closing as this request is not approved for more than 30 days');
gs.info(ritmGR.getRowCount());
ritmGR.update();
}
Please help..!
Thanks ahead
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2025 11:44 AM
Hello @Raji15 ,
There is a syntax error in the encoded query. Try this:
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addQuery('cat_item', 'fcb5900a1bdc82104db699f2b24bcb75');
ritmGR.addQuery('sys_created_on', '<=', gs.beginningOfLast30Days());
ritmGR.addQuery('stage', '!=', 'complete');
ritmGR.addQuery('approval', '!=', 'approved').addOrCondition('approval', 'NULL');
ritmGR.query();
while (ritmGR.next()) {
ritmGR.setValue('state', '4');
ritmGR.setValue('close_notes', 'Closing as this request is not approved for more than 30 days');
ritmGR.update();
}
And, as @Medi C mentioned, make sure the "Run as" user has the permission to update these records.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2025 04:17 AM
Hello @Raji15 ,
Can you please export that Scheduled Job to XML and attach it here for further analysis?
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2025 08:20 AM
Hi,
This is working as expected. Thank you so much. But The request state is not getting changed I want the request state to be changed to closed_incomplete.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2025 10:12 AM
Hello @Raji15 ,
It's been two weeks so please help me understand the current issue.
Are you saying you got your script to run as a Scheduled Job now, and it's updating the Close Notes of the RITM now, but not the State? Or is it updating the State to something, but not to Closed Incomplete?
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2025 11:16 AM
Hello,
I'm sorry for not clear before.
I am saying with the above script I am able to change the state of RITM to closed_incomplete and approval to Rejected.
But It is not changing the Request_state to closed Incomplete. Only the RITM state is changing not the Request. Help me with that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2025 12:21 PM - edited ‎04-11-2025 12:23 PM
Hello @Raji15 ,
Thanks for the clarification. So you want the parent of the RITM (the REQ) to be updated as well.
Looking at your original post there is no line in your script that would do that, so that's why it's not happening. And, at least OOTB, ServiceNow has no logic to update the REQ state when the RITM gets closed as incomplete.
You would need to implement this logic yourself. But you need to be aware that a REQ can have multiple RITM related to it. When all of them get closed incomplete it would make sense to close the REQ as incomplete as well. But what should be the REQ state when some of its RITM get closed completed, and some others incomplete? That's something you would need to discuss with your Request Management process owner first.
Once there is an alignment and you still want to ahead you would need to implement some Business Rule or Flow that triggers when a RITM gets closed incomplete. It would need to go through these steps:
- Check if there are any other sibling RITM related to this REQ, and look at their state.
- If there are no other sibling RITM, or all of them are closed incomplete set the REQ "Request state" to closed incomplete as well.
- If some of them are still active, don't do anything.
- If some are complete and some are incomplete, proceed as per the internal alignment.
PS: This should have been a new Community Question, because your original question did not mention updating the REQ, and was answered two weeks ago, even though you did not mark it as answered.
Regards,
Robert