- 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:03 PM
use global.DurationCalculator()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 02:15 PM
Thanks.. I have used it this way
var dc = new global.DurationCalculator();
and i m getting the below error 😞
JavaException: java.lang.SecurityException: Illegal access to private script include DurationCalculator in scope rhino.global being called from scope x_opt_euts_intake

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 02:19 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2018 02:19 PM
I would suggest create a copy of DurationCalculator script include in your Application scope and then use 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:20 PM
No why would you duplicate the code?? Just change the Accessible from on the script include