Incidents Updated 3 business days ago

pdom
Mega Expert

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

11 REPLIES 11

Inactive_Us1474
Giga Guru

Try using daysAgo(3); and compare it with last updated date.


Let me know if this does not helps.


I have tried this function, however this does not calculate business days. It only considers calendar days


Paramahanns
Tera Expert

did you get this problem fixed.


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