- 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 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 01:44 PM
Thanks Sanjiv @sanjivmeher. There were too issues. one in scoped application,
usrTZ = startDateBeg.getUserTimeZone();
This line is not working and i have to use gs.getSession().getTimeZoneName(); and another thing is there is class DurationCalculator he has used and he mentioned in that class, he defined the two methods.. Is it the script include name? and if so it doesnt makes sense.. rit?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 01:47 PM
It is out of box function
The script include 'ScheduleUtils' utilizes DurationCalculator, which is defined out of box
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 01:59 PM
This is what i got when i logged the error
ReferenceError: "DurationCalculator" is not defined.