Where will I effectively insert a/the business calendar in this Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 08:39 AM
Hello all,
I have a requirement to auto-populate an End Date, based on the value of Plan Period (30, 60, or 90 Days) and Start Date.
The script below works fine, except that it does not factor the Business Calendar (holidays and weekends) into it's calculations.
HOW or WHERE do I insert the Business Calendar?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var pPeriod= g_form.getValue('u_plan_period');
var pPeriodV= parseInt(pPeriod);
var pStartDate = new Date(getDateFromFormat(newValue, g_user_date_format));
//add 5 days to the selected date.
pStartDate.setDate(pStartDate.getDate() + pPeriodV);
var pStartDateStr = formatDate(pStartDate, g_user_date_format);
g_form.setValue('u_plan_end_date',pStartDateStr);
}
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 08:45 AM - edited 07-18-2024 08:46 AM
Hi @Hola Ola ,
Check the below post, it will guide you.
Calculate the business duration using a schedule
Mark this as Helpful / Accept the Solution if this helps
Mark this as Helpful / Accept the Solution if this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 08:47 AM
You need to use a schedule called 8-5 weekdays excluding holidays
Here's a sample script that adds days with schedule (global application)
var dc = new DurationCalculator();
dc.setStartDateTime(gs.now()); //input present date
dc.setSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); //Sysid of schedule: 8-5 weekdays excluding holidays
var durationSeconds = 1*24*60*60; // number of seconds in 1 day
dc.calcDuration(durationSeconds);
//dc.getEndDateTime() gives the present date + 1 day (in datetime format)
Here's a sample script that adds days with schedule (scoped application)
var startDate = new GlideDateTime();
var days = 2;
var dur = new GlideDuration(60 * 60 * 9 * 1000 * days);
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');//schedule : 8-5 weekdays excluding holidays
var endDate = schedule.add(startDate, dur);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 09:10 AM
Hi @Hola Ola ,
Please refer to below thread:
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thanks & Regards,
Sumanth Meda