Calculate duration based on schedule(Using Business Rule)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2017 02:03 AM
I need to be able to calculate the difference between two date fields in days based on a schedule using Business Rule (business days),. E.g. If start date is 01/03/2014 and end date is 08/03/2014, I want this answer to be 5 days (as 2 days out of the 7 are weekend days ).
There is a mention of this on the Wiki but it talks about packages.com and doesn't seem to work.
I have also seen 'GlideSchedule' referenced but not how to use it.
Has anyone got any thoughts please? Your help would be much appreciated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2017 03:06 AM
Take a look at this discussion.
if your instance is either on Calgary or above releases then you don't need to worry about packages as SN supporting these functionalities using APIs

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2017 09:56 AM
Use GlideSchedule API. Your code will look like this
var sched = new GlideSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); //sys_id of your schedule goes here
// Get duration based on schedule/timezone
var dur= (sched.duration(new GlideDateTime(<start date>), new GlideDateTime(<end date>)).getDurationValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2017 09:40 AM
I tried your approach below s my code but it gives me wrong output.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var startDateTime =new GlideDateTime(current.start_date);
var endDateTime =new GlideDateTime(current.end_date);
var sched =new GlideSchedule('sys_id', '08fcd0830a0a0b2600079f56b1adb9ae'); //8-5 weekdays
var dur= (sched.duration(startDateTime,endDateTime ).getDurationValue());
gs.log('the t time is'+dur , 'datevalidation');
})(current, previous);
Output is the t time is00:00:00
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2017 12:59 AM
Hi Pardhu,
You can find the diiference between two dates using schedule.
1.create business rule on between two dates.
2. call that business rule in script Actions.