- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2025 02:10 AM
Hi Team,
I need urgent assistance.I've created the scheduled job below, which runs every 1 minute (repeat interval: periodically).
The requirement is to set the state of the task to "Open" and clear the "Assigned to" field if the task is not closed within 5 minutes of its creation.
Example:
If a task is created at 1:00 PM IST and is not closed by 1:05 PM IST, then the system should update its state to Open and clear the Assigned to field.
Although the below code works, I'm facing an issue where the job performs the update before 5 minutes have passed. In some cases, it's reopening the task within just a few seconds of creation.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2025 04:15 AM
try to use addSeconds() method and give seconds for 5mins and 6 mins in that method
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 04:11 AM
added the logs.
There's no difference between fiveMinutesAgo and SixMinutesAgo. Both the timings fetched is same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2025 04:15 AM
try to use addSeconds() method and give seconds for 5mins and 6 mins in that method
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:21 AM
Would you mind closing your earlier questions by marking appropriate response as correct?
Members have invested their time and efforts in helping you.
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 03:41 AM
Hello @PK14
var taskGr = new GlideRecord('sc_task');
var now = new GlideDateTime();
var fiveMinutesAgo = new GlideDateTime();
fiveMinutesAgo.addMinutes(-5);
taskGr.addQuery('assigned_to', '16562d1ddbcb9490daad7f93e296195f'); //ABC
taskGr.addQuery('assignment_group', '14d1f5446f86a100c80e175e5d3ee4c0'); //Support
taskGr.addQuery('state', 'NOT IN', '3,4'); // Closed Complete or Closed Incomplete
taskGr.query();
while (taskGr.next()) {
var created = new GlideDateTime(taskGr.sys_created_on);
if (created.getNumericValue() <= fiveMinutesAgo.getNumericValue()) {
if (taskGr.state != '1') {
taskGr.state = '1'; // Open
taskGr.assigned_to = ''; // Clear assignment
taskGr.work_notes = "Auto-reopened: Not closed within 5 minutes of creation.";
taskGr.update();
gs.info('Task ' + taskGr.number + ' reopened after stuck > 5 mins');
}
}
}
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2025 07:36 AM
Hello @PK14
Did you tried with my solution not sure if you had look on it or not.
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.