How to Auto-Close Resolved Cases (5 Business Days)

Rob Sestito
Mega Sage

Hey Everyone!

So, I have a scheduled job that runs - to auto-close resolved cases. When it first was put together for Go-Live, it was supposed to be set for 5 business days, however (before i took this current position), it was set for 1 business day as a test and then never touched again. (seems silly)..

Here are the conditions and script to current job:

Run: Periodically

Repeat Intervals: [Days] 0

Hours: 01:00:00

Run Script:

// Close incidents after 5 business days

var days = -7;

// Business days exclude Saturday and Sunday

var day = new GlideDateTime(gs.nowDateTime());

//var weekday = day.getDayOfWeek();

//days = days - 2;

day.addDays(days);

// Find resolved incidents

gs.log('SJ Auto-close hr cases looking for cases resolved before ' + day.getDisplayValue());

var hr_case = new GlideRecord('hr_case');

hr_case.addQuery('state', '20');

hr_case.addQuery('sys_updated_on', '<=', day);

hr_case.query();

while (hr_case.next()) {

gs.log('SJ Auto-close cases found resolved case ' + hr_case.number + '. Was updated on ' + hr_case.sys_updated_on);

hr_case.state = '3';

hr_case.update();

}

Now originally, var days = -7; was set to -1 and I was told if I want to do 5 business days excluding weekend, then I needed to set that to the -7.

System Properties, Number of days (integer) after which Resolved incidents are automatically closed. Zero (0) disables this feature: This is set to 5 (which I changed as well, before it was set to 1).

During some testing, I changed the System properties "number of days" to 2 and left the script as it was to start with. A Case was auto closed after 2 days, 6 hours, 44 minutes.

Then I changed the system properties "number of days" to 5 - and change the script from var days = -1; to var days = -7;

And then my case auto closed 3 days. 2 hours, and 29 min.

From the information I have provided, is anyone able to see/notice what I need to change in order to get this corrected? (not sure if it matters, but my first test was on a Monday, second test was on a Thursday).

Thanks so much in advance!

-Rob

1 ACCEPTED SOLUTION

Rob Sestito
Mega Sage

Much later on this - but I went a different route on this.

Ended up adding in all our company's schedules within the system. Edited Workflow HRI Case User Acceptance - also created a system property which looks at HR Core Case, rather than the OOB property that controls the Incident Table.

Stages that I had to adjust were:

  1. Timer
  • Duration
  • Schedule Based on
  • Schedule

Then I also adjust the notification that goes out as well to fit our format. Also, OOB this sends the notifications to the Subject Person. I changed that to send to Requestor.

From this, I was able to control when HR Cases auto-close within 5 business days.

View solution in original post

18 REPLIES 18

Michael Fry1
Kilo Patron

Seems like it would be easier to use the Conditional script to control when this runs, something like this:


Screen Shot 2017-07-10 at 10.54.04 AM.png



function notweekend() {


      var now = new Date();


      var day = now.getDay();


      var result = false;


      if(day != 6 || day != 7) {


              result = true;


      }


      return result;


}


notweekend();


Thanks for your reply Michael,



That seems like a good idea. I will give that a shot. Since I have to wait practically a full week for this to test, I will get back to you next week if this works. haha



sorry - and thank you!



-Rob


quick question from your reply Michael -



Would I need to take out the "run script" in order for the conditional script to run? Or would the conditional script take over?



Thank you!


-Rob


You should remove this from your run script:


// Close incidents after 5 business days


var days = -7;



// Business days exclude Saturday and Sunday


var day = new GlideDateTime(gs.nowDateTime());


//var weekday = day.getDayOfWeek();



//days = days - 2;


day.addDays(days);