Testing autoclosure of incidents manually

Gagandeep
Tera Contributor

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

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

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;

 

View solution in original post

2 REPLIES 2

asifnoor
Kilo Patron

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;

 

Thanks Asif 🙂