- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 01:19 PM
The below script does add date based 8-5 Business days and it works fine. But i have a requirement, where it needs to do the subtract. It didnt work.. Could anyone of you help?
var date = this.getParameter('sysparm_date');
var dueDays = this.getParameter('sysparm_dueDays');
dueDays = 3;
var nowgdt = new GlideDateTime(date);
// The name of the schedule
var myScheduleName = '8-5 weekdays excluding holidays';
var dueWorkingHours = 9;
// The amount of time we want for the duration
var dueSeconds = dueDays*dueWorkingHours*60*60;
var leadTime = new GlideDuration(dueSeconds*1000);
//gs.error('Kailash' + leadTime);
// Calculate the Due Date!
var dueDateGdt;
var schedRec = new GlideRecord('cmn_schedule');
if (schedRec.get('name', myScheduleName)) {
var sched = new GlideSchedule(schedRec.sys_id);
//leadTime *=-1;
//gs.error('Lead time' + leadTime);
dueDateGdt = sched.add(nowgdt, leadTime, '');
}
var time = dueDateGdt.getDisplayValue();
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 01:23 PM
This thread should help
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 02:22 PM
Any future upgrade wont happen to that script include if you update it.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 02:33 PM
Thanks Sanjiv and Abhinay.. You are right, The specific script include is accessible from Global scope only and it caused the issue. I will make it accessible from all applications after talking to platform operations team in my company..
One quick explanation required. in the example, they are calculating the duration like below
var duration = dc.calcScheduleDuration(endDate, startDateBeg);
In the official documentation, start time and end time are reversed, and i believe, the method 'calcScheduleDuration' sets the 2nd argument only
DurationCalculator - calcScheduleDuration(String startTime, String endTime)
Gets the actual duration between startTime and endTime within the already-specified schedule and optionally overridden timezone. Sets this.endDateTime (for completeness), this.seconds, andthis.totalSeconds.
Sets this.endDateTime (for completeness), this.seconds, and this.totalSeconds.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 02:41 PM
It sets the value in the variables defined in the initialization of script include. But shouldn't matter.
If you have two dates date1 and date2 and if date 1 is less than date2, use date1 as start and other as end
initialize: function() {
this.startDateTime = this._getGDT();
this.endDateTime = this._getGDT();
this.schedule = null;
this.timezone = gs.getSession().getTimeZoneName();
this.seconds = 0;
this.totalSeconds = 0;
this.lu = new GSLog('com.glide.relative_duration.log', this.type);
},
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 02:42 PM
What are you looking at it specifically. This will calculate the duration based on a schedule between start date/time and end date/time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 02:44 PM
My actual issue got resolved.. what i wanted to know is, does the positioning of the argument in the calcScheduleDuration matters or not but from sanjiv's reply , it sounds like it will jus look at the shorter of those two dates and consider the smaller one as start time and the larger one as the end time and sets the duration to it..