Add time limit on Expected delivery

Jyothi76
Tera Contributor

Requirement:

Add time limit for expected delivery based on user's selection of drop-down[Delivery Type: Normal Delivery - 5 days, Express Delivery - 3 days, Express Delivery - 2 days and Express Delivery - 1 day].
In form we have below 2 variables,
1. Delivery Type[Select Box] - In this we have 4 options[Normal Delivery - 5 days, Express Delivery - 3 days, Express Delivery - 2 days and Express Delivery - 1 day].
2. Express delivery[Date/Time].
So here, when we select "Delivery Type" the "Expected delivery" field will auto-populate the date/time.
For example:
User/Me trying  to submit the request on 19/06/2025 and the user/me select the "Delivery Type: Normal Delivery - 5 days", in "Expected delivery - we need to auto-populate the date/time is 25/06/2025".
Note: The Expected delivery will populate based on "Delivery Type", if it 5days,3days,2days and 1day - means we need to calculate the date - based on user's[means Singapore user's] selection from date of ticket submission, and in this we need to exclude Singapore public holidays, Saturdays and Sundays and if public holiday falls on weekends, then the following "Monday" is off day.

Jyothi76_0-1750304938219.png

Thanks,
Jyothi

 

11 REPLIES 11

Hey Jyothi,

If you follow this approach, this wont work in year 2026.

Thanks

@Jyothi76 

client callable script include should not have initialize() method, please fix that

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

venkat917181
Tera Expert

Hey Jyothi,

open cmn_schedule table in your instance to know the holiday schedule of your organisation. 

In your scenario you have to create onchange client script which sends  "delivery type". In script include use cmn_schedule and caluclate the time. 

venkat917181_0-1750311394575.png

 

Hi @venkat917181,

This is the schedule,

Jyothi76_0-1750312880910.png



Thanks,
Jyothi

Hey Jyothi,

Please mark it helpful if it helped you.

This code chunck will help you.

---------------------------------------------------------

var schedule = new GlideSchedule();

var scheduleLoaded = schedule.load(scheduleName);

if (!scheduleLoaded) {

gs.error('Schedule not found: ' + scheduleName); /

/ Fallback to manual calculation if schedule not found return this._calculateManuallyWithScheduleCheck(startDateStr, businessDays, scheduleName);

} /

/ Create start date/time (9 AM Singapore time)

var startDateTime = new GlideDateTime();

startDateTime.setDisplayValue(startDateStr + ' 09:00:00'); /

/ Since Singapore Holidays schedule contains only holidays,

// we need to manually add business days while checking the schedule

var currentDate = new GlideDateTime(startDateTime);

var businessDaysAdded = 0;

while (businessDaysAdded < businessDays) {

currentDate.addDaysLocalTime(1); /

/ Check if current date is a business day

if (this._isBusinessDayWithHolidaySchedule(currentDate, schedule)) {

businessDaysAdded++;

}

}

// Set delivery time to 9 AM

var resultDate = currentDate.getDisplayValue().split(' ')[0] + ' 09:00:00';

return resultDate;