- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2022 09:44 AM
I have a scheduled job running with the following code on auto closure of incidents. I want the script to auto close incidents only on weekdays. Also, I want to test it manually in orer to make sure that it will trigger the system property and auto close the incidents correctly. Below is the script for scheduled job:
autoCloseIncidents();
function autoCloseIncidents() {
var ps = gs.getProperty('glide.ui.autoclose.time');
var pn = parseInt(ps);
var queryTime = new GlideDateTime();
queryTime.addDaysUTC(-pn);
if (pn > 0) {
var gr = new GlideRecord('incident');
gr.addQuery('incident_state', '6');
gr.addQuery('resolved_at', '<', queryTime);
gr.query();
while (gr.next()) {
gr.incident_state = '7';
gr.close_notes = 'Incident Closed by system';
gr.active = false;
gr.update();
gs.eventQueue('incident.closed', gr, gr.caller_id);
}
}
}
@asifnoor please guide
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2022 09:48 AM
Hi,
In the scheduled job, you have a condition field, there you can check if the current day is a weekday or not.
Here is the sample code snippet that you can try.
var result = true;
var gdt = new GlideDateTime();
if(gdt.getDayOfWeekUTC() == 6 || gdt.getDayOfWeekUTC() == 7 )
result = false;
return result;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2022 09:48 AM
Hi,
In the scheduled job, you have a condition field, there you can check if the current day is a weekday or not.
Here is the sample code snippet that you can try.
var result = true;
var gdt = new GlideDateTime();
if(gdt.getDayOfWeekUTC() == 6 || gdt.getDayOfWeekUTC() == 7 )
result = false;
return result;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2022 09:37 AM
Thanks Asif 🙂