- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2019 01:10 PM
Hi All ,
I have to calculate 5 working days using US holidays calendar schedule based and i try to use below script.
Kindly check and help me how to use this on change client script and script include in the same script.
I have tried my level its not working pls help me to fix this issue
BACKGROUND SCRIPT
var cal = GlideCalendar.getCalendar('b13be85ddbbe47408567fd7aae9619f1');
//table:global
gs.print(nowPlusNCalDays(6));
function nowPlusNCalDays(days) {
//set the calendar sysid to your calendar
//var cal = Packages.com.glide.schedule.GlideCalendar.getCalendar('b13be85ddbbe47408567fd7aae9619f1');
var cal = GlideCalendar.getCalendar('bea4c03cc611227801d411166792a145');
var duration = new GlideDuration();
//specify the number of milliseconds to add, based on calenadar
//this will add 1000ms*60sec*60mins*8hour(biz hours in a day)*(days parameter)
//the calculation makes more sense if you think of it as how many business hours to add, not days.
duration.setValue(1000*60*60*8*days);
var actualDateTime = new GlideDateTime();
gs.print(actualDateTime);
var newDateTime = new GlideDateTime();
actualDateTime.setDisplayValue(gs.nowDateTime());
newDateTime.setValue(cal.add(actualDateTime,duration));
return newDateTime.getDisplayValue();
}
IF I select 5BD it will calculate 5 working days and if i select 15BD it will get the value 15 based on field change.
Please check and help me
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2019 01:50 PM
change your script includes to below. make sure client callable is checked.
var QuarantineValidate = Class.create();
QuarantineValidate.prototype = Object.extendsObject(AbstractAjaxProcessor,
{
ValidateDate: function() {
var days = this.getParameter('sysparm_needed_by');
var cal = new GlideSchedule('b13be85ddbbe47408567fd7aae9619f1');
var currentDateTime = new GlideDateTime();
currentDateTime.setDisplayValue(gs.nowDateTime());
var dur = new GlideDuration();
dur.setValue(60*60*24*1000*days);
var newDateTime = cal.add(currentDateTime, dur, '');
return newDateTime.getDisplayValue();
} ,
type: 'QuarantineValidate'
});
change client script to below
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '')
{
return;
}
var val=g_form.getValue('u_euc_ci_status');
if (val == 51){
var ga = new GlideAjax('QuarantineValidate');
ga.addParam('sysparm_name','ValidateDate');
ga.addParam('sysparm_needed_by', val);
ga.getXML(callBack);
}
function callBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue('u_quarantine_end_date', answer); // put in the variable name you want to show or hide according needed by date
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2019 01:25 PM
Try using
var sched = new GlideSchedule('55ebbbf15f002000b12e3572f2b47714');
var currentDateTime = new GlideDateTime();
currentDateTime.setDisplayValue(gs.nowDateTime());
var dur = new GlideDuration(60 * 60 * 24 * 1000 * 5); //5 days
var newDateTime = sched.add(currentDateTime, dur, '');
gs.print(newDateTime.getDisplayValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2019 01:44 PM
I got following reply ...
Adding 5 Days to 2019-06-04 16:42:20 using schedule null ran too long without hitting schedule times - using simple date addition
*** Script: 2019-06-09 16:42:20
Its not calculating exclude holidays , Its simply adding 5 days to current date

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2019 01:44 PM
Did you change the sysid of calendar ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 11:19 AM
Thanks Mike...
Please help me
How to get RITM & Catalog Item details from sysapproval_approver user Based details.
Pls check the below URL and help me fix the issue