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

Okay - that's what I was thinking but wasn't 100%.


Thank you very much Sir for the clarification!


Test has commenced.



-Rob


Good Morning Michael,



Are you able to check out my last update to this thread and see where I am having an issue? The auto-close Case I created for my test still closed in the middle of day 3 from being open.



Thanks in advance,


-Rob


You have a scheduled job that looks like below? and what's happening? In the run script I'd probably replace 'day' so it gets the right day:



Screen Shot 2017-07-18 at 9.01.07 AM.png


Sadasiva Reddy
Giga Guru

Hi Robert,



follow the OOB business rule for incident and write accordingly for the cases.. change to   var ps = 5;


find_real_file.png



regards,


Sadasiva



Please mark helpful/ correct based on the impact


Thanks for your reply Sadasiva,



I am going to attempt Michael's option first and go from there.



In terms of your option, are you saying to take out the gs.getProperty('glide.ui.autoclose.time'); completely from var ps = and replace that with the integer 5?



so that line will look like this: var ps = 5;



Thank you in advance,


-Rob