Auto close resolved incidents after 3 business days

snuser10
Kilo Expert

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!

14 REPLIES 14

This does it by calendar days not business days so it doesn't work


David OBrien
Kilo Guru

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.


Hi David,



Could you please clarify this line, I didnt get here





  1. var test = strCloseDays * busHoursPerDay * 60 * 60 * 1000;  

thank you David.   I used something similar using script include and scheduled job.


kemmy1
Tera Guru

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