- 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-27-2025 11:36 AM
Hello @Raji15,
Please add "Run as" to your form layout and make sure its value is "System administrator" or a user with enough permission to perform the update
If that doesn't resolve the issue, please share the logs if there are any errors thrown.
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2025 04:02 AM
Hi @Medi C , Yes I did that
I am not even able to see the logs in system logs. I used the below code still no luck .
- 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:03 AM