Auto close resolved incidents after 7 business days

chaitusnow
Mega Contributor

Hi All,

I have a requirement for Auto Close incidents for 7 business days.

I know that we have an OOB business rule which closes incidents based on calendar days. It is not applicable for Business days.

Can any one share the information or code for auto closing incidents for 7 business days.

Regards,

KVC.

8 REPLIES 8

Hi Ajay,

 

The article you shared works for calendar days. It wont work for Business days.

Thanks for sharing the article.

Regards,

Ajay.

Hi Yusuf,

Below code will work,

// This script automatically closes incidents that are resolved
// and haven't been updated in a chosen number of days. You
// can set this number as a property in System Properties.
// If you want a comment placed in the incident, uncomment the
// 'gr.comments' line below.

var ps = gs.getProperty('glide.ui.autoclose.time');
var pn = parseInt(ps);

if(pn > 0){
   //Get a schedule by name to calculate duration
   var schedRec = new GlideRecord('cmn_schedule');
   schedRec.get('name', '8-5 weekdays');
   if (typeof GlideSchedule != 'undefined')
      var sched = new GlideSchedule(schedRec.sys_id);
   else
      var sched = new Packages.com.glide.schedules.Schedule(schedRec.sys_id);

   //Get the current date/time in correct format for duration calculation
   var actualDateTime = new GlideDateTime();
   actualDateTime.setDisplayValue(gs.nowDateTime());

   //Query for resolved incident records
   var gr = new GlideRecord('incident');
   gr.addQuery('state', 6);
   gr.query();
   while(gr.next()){
      //Close any records that have not been updated in 'pn' number of days
      //Date difference calculated based on specified schedule
      var dif = sched.duration(gr.sys_updated_on.getGlideObject(), actualDateTime).getDayPart();
      if(dif >= pn){
         gr.state = 7;
         gr.active = false;
         //gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';
         gr.update();
      }
   }
}

For more information, please refer Calendar or Schedule-based Incident Autoclose

Regards,
Ajay

 

 

chaitusnow
Mega Contributor

Hi Ajay,

 

Thanks for your response. It's not working as expected. I am trying to solve it.

 

Thanks,

KVC

Prasad Dhumal
Mega Sage
Mega Sage

Hello Chaitusnow,

Create Shceduled Job.

I am sharing a Image, Make same changes according to that.

 

 

 

find_real_file.png

Add this Code : 

var gr = new GlideRecord('incident');
gr.addEncodedQuery('resolved_atRELATIVEGT@dayofweek@ahead@7');
gr.query();
while(gr.next())
{
gr.setValue('u_status',closed);
gr.update();
}

 

Please mark my answer as correct and close the thread so that others can also benefit.

Regards

Prasad Dhumal