- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 07:10 AM
Hello,
I have a requirement where if there is an active record found on task table assigned to a specific group, the scheduled job should execute and mark the record closed and inactive. I was able to achieve the 2nd part of the script to close the tasks as below:
I need some help to get the code which would keep checking the table for any ACTIVE task assigned to the group and as soon as it finds one, the job should close the task.
Also, this job should execute only on Saturday and at 15 minute interval.
Any help on this would be appreciated.
Regards
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 07:16 AM
Hello @ashpan
Please add the below script in the scheduled job -
(function executeScheduleJob() {
var today = new GlideDateTime();
var dayOfWeek = today.getDayOfWeek(); // 1 = Monday, 7 = Sunday
if (dayOfWeek != 7) { // 7 means Saturday (modify if needed)
gs.info("Scheduled job skipped - Not Saturday");
return;
}
var groupSysId = "<sys_id_of_the_group>"; // Replace with actual sys_id of the assignment group
var gr = new GlideRecord("task");
gr.addQuery("assignment_group", groupSysId);
gr.addQuery("active", true);
gr.setLimit(500);
gr.query();
while (gr.next()) {
gr.state = 3; // 3 = Closed Complete (Modify as per required state)
gr.active = false;
gr.assigned_to.setDisplayValue("Test User"); // Modify as needed
gr.update();
}
gs.info("Scheduled job executed - Closed tasks for group
: " + groupSysId);
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOw
NeEISQCY
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 07:16 AM
Hello @ashpan
Please add the below script in the scheduled job -
(function executeScheduleJob() {
var today = new GlideDateTime();
var dayOfWeek = today.getDayOfWeek(); // 1 = Monday, 7 = Sunday
if (dayOfWeek != 7) { // 7 means Saturday (modify if needed)
gs.info("Scheduled job skipped - Not Saturday");
return;
}
var groupSysId = "<sys_id_of_the_group>"; // Replace with actual sys_id of the assignment group
var gr = new GlideRecord("task");
gr.addQuery("assignment_group", groupSysId);
gr.addQuery("active", true);
gr.setLimit(500);
gr.query();
while (gr.next()) {
gr.state = 3; // 3 = Closed Complete (Modify as per required state)
gr.active = false;
gr.assigned_to.setDisplayValue("Test User"); // Modify as needed
gr.update();
}
gs.info("Scheduled job executed - Closed tasks for group
: " + groupSysId);
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOw
NeEISQCY
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2025 06:33 AM
Thanks Shivalika.
I was able to achieve the code with the help of your suggestion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 07:19 AM - edited 03-19-2025 07:21 AM
Hello @ashpan
Code something can be like this
//Note: Make sure to replace <sys_id of the group> with the actual sys_id of the group you are targeting.
var filterquery = "assignment_group=<sys_id of the group>^active=true";
var gr = new GlideRecord("task");
gr.addEncodedQuery(filterquery);
gr.setLimit(500);
gr.query();
while(gr.next()) {
gr.state = '3'; // Assuming '3' is the state for 'Closed'
gr.active = false;
gr.assigned_to = "Test User"; // Update as needed or pass sys_id of user
gr.update();
}
Setup your scheduled job as below
- Set the Run field to Weekly.
- Select Saturday and set the Time to the desired start time.
- Set the Repeat Interval to 15 minutes.
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
03-19-2025 07:27 AM
Please check the below Image
code :
Please Mark it helpful
Regards
Priyatam