Incidents Updated 3 business days ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 07:10 PM
Hello,
I have to check if an Incident last update date is 3 business days ago, then close the record. The OOTB business rules only checks for 3 calendar days.
I am working below background script to check if Incident update is 3 business days old, but it is not giving positive result. Please point me to right direction
I have tried two different approaches, neither of it working
Approach 1:
var gr = new GlideRecord('incident');
gr.addQuery = ('number','INC0010406');
gr.query();
var dc = new DurationCalculator();
var scheduleSysId = gs.getProperty('sag.businesshour.schedule');
dc.setSchedule('ScheduleSysId'); // this is the sys_id of 8-6 weekday schedule in your instance.
dc.setTimeZone('GMT');
var dur = dc.calcScheduleDuration(gs.nowDateTime(),gr.sys_updated_on)/3600;
if(dur>30){ //each working day is 10 hrs, so 3 working days is 10*3 30 hrs
gs.print("duartion is greater than 3 days");
}else gs.print("duration is less than 3 days");
Approach 2 :
// Get the current date/time in correct format for duration calculation
var currentDateTime = new GlideDateTime();
var updatedon ='';
var gr = new GlideRecord('incident');
gr.addQuery = ('number','INC0010406');
gr.query();
updatedon = gr.sys_updated_on.toString();
var startDate = new GlideDateTime('updatedon');
var endDate = new GlideDateTime('currentDateTime');
var schedule = new GlideSchedule();
schedule.load('sag.businesshour.schedule'); // loads "8-5 weekdays excluding holidays" schedule
var duration = schedule.duration(startDate, endDate);
gs.print(duration.getDurationValue()); // gets the elapsed time in schedule

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 07:59 PM
Try using daysAgo(3); and compare it with last updated date.
Let me know if this does not helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 09:09 PM
I have tried this function, however this does not calculate business days. It only considers calendar days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 09:00 AM
did you get this problem fixed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2017 03:44 AM
Hi Padmini Dommeti , Paramahanns Rathnakumar
Are you able to succeed with this..We are facing same problem. Could you please share the solution/tips/work around
Thanks
Prici