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

Yes..


replace that line with var ps =5; and modify field names and queries accordingly..



Regards,


Sadasiva



Please mark helpful/ correct based on the impact


Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

I did a post about it here, 3 Business days, but that is easy to just change:



How to close ticket after 3 business days



//göran


Thanks for the reply and information to your post Goran!



I just checked out the Relative Durations from my SN Test Instance and here is what is shown:



// 3 business days by 4pm if before 10am


var days = 3;


// If the current time is after 10:00, add another day


if (calculator.isAfter(calculator.startDateTime, "10:00:00")) {


    days++;


}



calculator.calcRelativeDueDate(calculator.startDateTime, days, "16:00:00");



Which above shows very true to what happened to my last test that I stated in my original post.



Could/Should I change this? Making the script look to 5 business days instead of 3? Along with all other changes that have been provided in this post?


You can just make your own 5 days duration and keep the oob 3 days alone 😃


Thanks Goran,



I actually went through your link you sent me about this type of Discussion (How to close ticket after 3 business days ) and created new ones to see if I can do some testing with that - and making the OOB 3 day to false.



Going to give that a try - Thanks again!



-Rob