Incident Auto close after 5 business days

vspk
Giga Expert

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?

4 REPLIES 4

Chuck Tomasi
Tera Patron

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


sharank1
Giga Contributor

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.




  1. autoCloseIncidents();
  2. function autoCloseIncidents() {
  3.   var ps = 5; // you can set the number of days as per your requirement
  4.   var pn = parseInt(ps);
  5.   if (pn > 0) {
  6.   var gr = new GlideRecord('incident');
  7.   gr.addQuery('state', 'xx'); // State when it is resolved
  8.  
  9.   gr.addQuery('sys_updated_on', '<', gs.daysAgoStart(pn));
  10.   gr.query();
  11.   while(gr.next()) {
  12.   gr.state = 'xx'; (give the value of your closed state)
  13.   //   gr.comments = 'Incident automatically closed after ' + pn + ' days in the Resolved state.';
  14.   gr.active = false;
  15.   gr.update();
  16.   }
  17.   }
  18. }


This will definitely help you. Let me know if you have any issues.



Thanks,
Sharan


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.


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