Scheduled Job: Auto-Close Resolved HR Cases
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @Everyone,
This scheduled job is designed to automatically close HR cases. It works by using an encoded query: when a case is in the Resolved state and has not been updated for more than 7 days, the job updates its state to Closed.
However, I recently noticed that the job is not functioning as expected. The logs show “Total cases closed: 0”, but no cases are actually being closed.
I suspect that the encoded query may not be returning the correct set of records that need to be closed. Further investigation is required to ensure the query logic correctly identifies eligible cases.
**Script Below**
(function autoCloseResolvedCases() {
var gr = new GlideRecord('sn_hr_core_case');
gr.addEncodedQuery('sys_updated_onRELATIVELE@dayofweek@ago@7^state=8');
gr.query();
var count = 0;
while (gr.next()) {
gr.state = 3; // Closed
gr.update();
gs.info('Auto Closed Record: ' + gr.number + ' | Last updated on: ' + gr.sys_updated_on);
count++;
}
gs.info('Auto Closed Records Total Count: ' + count);
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @mdshahvez11 ,
There seems to be an issue with your encoded query. There is no State field with a value equal to 8.
Please double-check and confirm that the correct value is being used for the State field.
Regards,
Huynh Loc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hello @Huynh Loc ,
I checked the instance and confirmed that the backend value for the “Resolved” state is 8.
Observations:
- Initially, the logs showed: Total closed records = 0.
- I tested the same scheduled job in Dev, and everything appeared to be functioning correctly.
- Later, in production, the same scheduled job started working unexpectedly, and all valid matching records were closed.
The tickets that were supposed to be closed on the 7th day (with no updates) were instead closed 7 days later, even though there were no changes made to the scheduled job.
Currently, over the past 5 days, I’ve been observing that:
- The scheduled job is running as expected
- Logs are being generated correctly
- Overall behavior appears normal
However, I am still unable to determine the root cause of the earlier issue.
Please let me know your thoughts on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @mdshahvez11 ,
Regards,
Huynh Loc
