
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 05:33 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2018 05:51 AM
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:
- 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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2017 05:43 AM
Case auto-closed still under 5 days. 3 days 6 hours.
From Auto-Close Resolved HR Cases:
Active: Check
Run: Periodically
Days: 0
Hours: 01:00:00
Conditional: Check with the following:
function notweekend() {
var now = new Date();
var day = now.getDay();
var result = false;
if(day != 6 || day != 7) {
result = true;
}
return result;
}
notweekend();
Run this script with the following:
// 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();
}
Relative Duration: (Name: 5 Business Days by 5pm - with the following): Note, I just changed this today - it was 3 days by 4pm before I modified it - could that have been the problem??
(Previous script):
// 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");
(New Script):
// 5 business days by 5pm if before 10am
var days = 7;
// 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, "17:00:00");
Then I also looked at the OOB Business Rule Incident Autoclose - changed what Pasala Reddy recommended above. By changing the var ps = gs.getProperty('glide.ui.autoclose.time');
to now be var ps = 5;
Does this all make sense - can anyone tell where I went wrong? was is all because of the relative duration being the old duration before i changed it??
thanks to all who have helped so far, and thanks in advance for possibly any more help that can be provided!
-Rob

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-27-2018 05:51 AM
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:
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2019 06:24 AM
Hi All,
Please share the code which is working for closing the incidents for 5 Business Days.
Regards,
Chaitanya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2019 06:58 AM
Hello Chaitanya,
I can show you my work, but if you are looking to do this for Incident Table, then you will need to adjust for that - as I am using HR Core Case Table.
I Edited the HRI Case User Acceptance from the Workflow Editor:
Within the Timer - Time is Up step, this is where you need to specify what you want for the timer. I think the system has some out of the box schedules ( don't quote me ) - but we built all our own and I think you might have to do this as well, if you have not done so already.
It probably won't be the same, but here are all my company's schedules that needed to be built out. Which helps with the timer within the Workflow HRI User Acceptance Workflow.
I can't go into detail on each of these, as it would be way too many screen shots.
Created a system properties from sys_properties.list (out of the box, Incident already has one)
For incident, in your filter navigator type in: system properties, then click on System. Within your system properties, Incident is already set on 7 days I believe:
and for the Business Rule 'Add User Acceptance State, we have as follows:
Condition:
previous.state != hr_Constants.CASE_AWAITING_USER_ACCEPTANCE && previous.state != hr_Constants.TASK_CLOSED_COMPLETE && current.state == hr_Constants.TASK_CLOSED_COMPLETE && !current.skip_automatic_user_acceptance_state
Script:
Not sure how much help this will be - but I hope some. Let me know if you have any more question and I will do my best to help!
Thanks,
-Rob