Glide schedule Subtract

kailashthiyagar
Kilo Guru

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();
1 ACCEPTED SOLUTION
14 REPLIES 14

Abhinay Erra
Giga Sage

use global.DurationCalculator()

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

Go to script includes and search for "DurationCalculator" and on the Accessible from "All Application scopes"

find_real_file.png

I would suggest create a copy of DurationCalculator script include in your Application scope and then use it.

No why would you duplicate the code?? Just change the Accessible from on the script include