Incident Auto close after 5 business days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2016 06:24 AM
Hi,
our client has a requirement to autoclose the incidents after 5 BUSINESS DAYS
The OOB brule works for continuous 5 days but I need the incidents closure after 5 Business days
How to implement this?
If scheduled Job is needed, how to write the schedule job to work only on business days?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2016 06:31 AM
Yes, you will need to create a scheduled job to do this yourself.
Option 1: Just start counting the days and use the day of the week to skip over Saturday and Sunday.
Option 2: If you have a different way of calculating business days, you need to create a schedule define. OOB, there is one for Mon-Fri 8-5. Check this thread for some helpful information. There's a business rule near the end that can help. Calculate duration based on schedule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2016 06:54 AM
Hi Sneha,
For your requirement, create a 'after' business rule on incident table. And in the advanced section please give the following 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() {
- var ps = 5; // you can set the number of days as per your requirement
- var pn = parseInt(ps);
- if (pn > 0) {
- var gr = new GlideRecord('incident');
- gr.addQuery('state', 'xx'); // State when it is resolved
- gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(pn));
- gr.query();
- while(gr.next()) {
- gr.state = 'xx'; (give the value of your closed state)
- // gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';
- gr.active = false;
- gr.update();
- }
- }
- }
This will definitely help you. Let me know if you have any issues.
Thanks,
Sharan

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2016 07:03 AM
Hi Sharan,
After reviewing the requirements... This will do 5 (calendar) days. Sneha's requirement was for 5 business days.
Also, putting it in a business rule means it only gets triggered when an incident is updated (either manually or by the system.) While this is normally quite frequent, it doesn't ensure it is run at the appropriate time. A scheduled job (hourly perhaps) is a better means for running such a script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2016 07:03 AM
I think this is the OOB Business rule and it does not handle the 'Business days' part of the requirement.
Calculating the difference between the dates with the help of a schedule would be the best approach to accomplish this requirement as Chuck as already mentioned earlier.
Thanks and Regards,
Aswin Siddalingam