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
‎05-05-2019 11:58 PM
Could someone help me on this?
I need to fetch Change records of Past 15 Business days from planned end date.
The above code snippet is not working properly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2021 10:38 PM
Hi,
How to check the if requested item is updated before 30 days one task has to create, else it has to display it's been thirty days you cannot create task from request. can anyone help with this..