Business rule to autoclose resolved incidents after a certain number of business days not working

bookman1502
Giga Expert

Hi,

My organization wants to create a new business rule to replace incident autoclose that will use business days instead of calendar days to determine when to close resolved incidents. To do this, I have created a business rule which references a schedule with a schedule entry that is all day and repeats every weekday. However, when I execute it either by putting it inside of a fix script and running it or telling a scheduled job to fire it, the incidents that were resolved more than 5 days ago don't seem to be closing. Here is the code:

// This script automatically closes incidents that are resolved

// and haven't been updated in the specified number of days.

// This number is a property in System Properties.

// To place a comment in the incident, uncomment the "gr.comments" line.

autoCloseIncidents();

function autoCloseIncidents() {

      gs.log('updated incident autoclose running');

      var i = 0;

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

      var pn = parseInt(ps);

      if (pn > 0) {

              var j = 0;

              var countdays = pn;

              var sid ='4a62d78a132e42001a1f58222244b074';

              var sched = new GlideSchedule(sid);

              gs.info(sched.getName());

              while(countdays!=0 || !sched.isInSchedule(d)){

                      var d = new GlideDateTime();

                      d.setDisplayValue(gs.daysAgoStart(countdays).toString());

                      if(!sched.isInSchedule(d)){

                              gs.log('not in Schedule');

                              pn++;

                              j++;

                      }

                      countdays--;

              }

             

              gs.log('Number of days: ' + pn);

              gs.log(gs.daysAgoStart(pn));

              var gr = new GlideRecord('incident');

              gr.addQuery('incident_state', '6');

              gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(pn));

              gr.query();

              while(gr.next()) {

                      gr.incident_state = '7';

                      i++;

                      //   gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';

                      gr.active = false;

                      gr.update();

              }

              gs.log('Number of incidents affected:'+ i);

      }

}

Does anyone have any idea what might be going on?

5 REPLIES 5

gtk
Mega Sage

do we need to create scheduled job or it, if yes can you give the steps to create the scheduled job.




i have a question, how SN calculate the Saturdays and Sundays