Reopen stuck Tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 05:33 AM - edited 07-16-2025 05:41 AM
Hi Team,
My requirement is to set the state to open if the ticket is in work in progress state for more then 15 minutes (doesn't close) when a ticket is assigned to automation.
I have written a schedule job which works but resets the ticket to open state before 15 minutes. I assume it is because of the "Repeat Interval" that has been set for 2 minutes. (Runs periodically).
Can you please assist on this. The task can be created anytime so based on that the scheduled job should work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 05:47 AM
I will suggest not to rely on sys_history_line table, but use a custom field to check when state changed to WIP.
Steps
1) before update business rule
Condition: State [Changes To] Work In Progress
Script:
current.u_wip_since = new GlideDateTime();
2) then update scheduled job and use that field for 15 mins check
Something like this
var now = new GlideDateTime();
var fifteenMinutesInMillis = 15 * 60 * 1000;
var taskGr = new GlideRecord('sc_task');
taskGr.addQuery('assigned_to', '16562d1ddbcb9490daad7f93e296195f'); // automation sys_id
taskGr.addQuery('state', '2'); // Work in Progress
taskGr.addNotNullQuery('u_wip_since'); // Must have WIP start time
taskGr.query();
while (taskGr.next()) {
var wipStart = taskGr.u_wip_since.getGlideObject();
var timePassed = now.getNumericValue() - wipStart.getNumericValue();
if (timePassed >= fifteenMinutesInMillis) {
taskGr.state = 1; // Reopen the task
taskGr.work_notes = "Task automatically reopened after 15+ minutes in 'Work in Progress' without closure by automation.";
taskGr.u_wip_since = ''; // Reset the field
taskGr.update();
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2025 08:12 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2025 02:15 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2025 05:09 AM
Hi @Ankur Bawiskar,
Please let me know, if "u_wip_since" is field that storing the time when state changed to WIP?