Auto close resolved incidents after 3 business days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2017 06:43 AM
Trying to figure out how to auto close an incident after 3 business days of being in resolved state. I tried following link (How to close ticket after 3 business days )however, end date here has the correct date but not correct time. Any one has a solution for that? Appreciate your help!
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2017 08:03 AM
This does it by calendar days not business days so it doesn't work

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2017 11:59 AM
You can deactivate the out of the box incident autoclose rule and replace it with something like this.
On line 6, you need to replace the 2 with however many business days you want to wait to autoclose.
On line 7, you need to replace the '12' with however many business hours are in your business day.
On line 8, you need to replace the 'IT Service Desk Hours' with the name of the schedule you want to use.
autoCloseIncidents();
function autoCloseIncidents() {
var strCloseDays = '2';
var busHoursPerDay = 12;
var schedID = 'IT Service Desk Hours';
var test = strCloseDays * busHoursPerDay * 60 * 60 * 1000;
var closeDays = parseInt(strCloseDays, 10);
var sched = null;
sched = new Packages.com.glide.schedules.Schedule(schedID);
var nowDt = new Packages.com.glide.glideobject.GlideDateTime();
var inc = new GlideRecord('incident');
inc.addQuery('state', '6');
while (inc.next()) {
var closeDt = inc.sys_updated_on.getGlideObject();
var closeInc = false;
if (sched != null) {
var closeDaysDur = new Packages.com.glide.glideobject.GlideDuration(closeDays * busHoursPerDay * 60 * 60 * 1000);
closeDt = sched.add(closeDt, closeDaysDur);
if (closeDt.getNumericValue() <= nowDt.getNumericValue()) {
closeInc = true;
}
} else { // If we don't have a schedule then just calc close date as calendar days
closeDt.addDays(closeDays);
var secs = gs.dateDiff(nowDt.getDisplayValue(), closeDt.getDisplayValue(), true);
if (secs <= 0) {
closeInc = true;
}
}
if (closeInc) {
inc.state = 7;
inc.active = false;
inc.closed_by = inc.resolved_by;
inc.update();
}
}
}
Hope that helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2017 12:08 PM
Hi David,
Could you please clarify this line, I didnt get here
- var test = strCloseDays * busHoursPerDay * 60 * 60 * 1000;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2017 12:51 PM
thank you David. I used something similar using script include and scheduled job.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2018 06:06 AM
I get the error messsage: Illegal attempt to access class 'com.glide.schedules' via script when I try to access my schedule, does anyone else get this?
We are on Kingston.
Lisa