- 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
‎04-13-2025 12:47 PM
Hi,
I have marked it as answered😊
Thank you for clarification.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2025 04:48 AM
Your scheduled job might not be working due to permissions, logging issues, or a faulty query. Since scheduled jobs run under a system user, try adding gs.log("Scheduled Job Started", "ScheduledJob"); to check if it's running. If the query isn’t fetching records, test it in Scripts - Background. To improve performance, use ritmGR.autoSysFields(false); before ritmGR.update();. If it still doesn’t work, consider using a Business Rule to auto-close requests older than 30 days or a Flow Designer for a no-code solution.