Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

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

_isBusinessDayWithHolidaySchedule: function(date, schedule) {

// Check weekend (Sunday = 1, Saturday = 7)

var dayOfWeek = date.getDayOfWeekUTC(); if (dayOfWeek === 1 || dayOfWeek === 7) { return false; } // Check if date is in the Singapore Holidays schedule // If the schedule contains this date, it's a holiday (not a business day) var checkDateTime = new GlideDateTime(date); checkDateTime.setDisplayValue(date.getDisplayValue().split(' ')[0] + ' 10:00:00'); // If the date is in the holiday schedule, it's NOT a business day var isHoliday = schedule.isInSchedule(checkDateTime); return !isHoliday; }

Hi @venkat917181,

I have written code but in this the "Expected delivery" date is auto populating based on "Delivery Type", but in this we need to populate the "Expected delivery" based on Singapore time zone, for example if I submit the request before 3pm Singapore time we need to calculate on 26-06-2025 to 2-06-2025 5 days the delivery type is "Normal Delivery - 5 days", so we need auto populate 02-06-2025, if we submit the request after 3pm we need to consider next business day which means 27-06-2025 to 03-07-2025, we need to populate in expected delivery 03-07-2025, how to add this timing before 3pm and after 3pm Singapore time in my script include and catalog client script. In the below image,
Normal Delivery - 5days - if we submit request before 3pm Singapore time, should calculate/count same day, if we submit request after 3pm Singapore time, should calculate/count next business day,
Express Delivery - 3 days, 2 days and 1 day.

Jyothi76_0-1750928442948.png

 






Script Include:

var DeliveryDateCalculator = Class.create();
DeliveryDateCalculator.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    isBusinessDayWithHolidaySchedule: function() {
        gs.info("jyothi SI entered ");
        var deliveryType = this.getParameter('sysparm_delivery_type');
        gs.info("jyothi SI deliveryType "+ deliveryType);
        var gdt = new GlideDateTime();
        gdt.setTimeZone('Asia/Singapore');
        gs.info("jyothi SI gdt "+ gdt.toString());

        var sch = 'f46034b0875aa29093e30d490cbb35ef';
        var duration;
           

        if (deliveryType == 'Normal Delivery') {
            gs.info("jyothi SI deliveryType if  ");
            duration = new GlideDuration(60 * 60 * 9.15 * 1000 * 5 );
        } else if (deliveryType == 'Express Delivery – 3 Days') {
            duration = new GlideDuration(60 * 60 * 9.15 * 1000 * 3);
        } else if (deliveryType == 'Express Delivery – 2 Days') {
            duration = new GlideDuration(60 * 60 * 9.15 * 1000 * 2);
        } else if (deliveryType == 'Express Delivery – 1 Day') {
            duration = new GlideDuration(60 * 60 * 9.15 * 1000 * 1);
        }

        gs.info("jyothi SI duration "+ duration.getDisplayValue());

    var schedule = new GlideSchedule(sch);
    gs.info("jyothi SI isInSchedule "+ schedule.isInSchedule(gdt));


    var finalval = schedule.add(gdt, duration);
    gs.info("jyothi SI finalval " + finalval);
       
    var finalDate = new GlideDateTime(finalval);
    gs.info("jyothi SI finalDate "+ finalDate.getDisplayValue());

   
        return finalDate;

    },

    type: 'DeliveryDateCalculator'
});

Catalog client script:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   var deliveryType = g_form.getValue('v_campus_printshop_delivery_type');
   


    var ga = new GlideAjax("global.DeliveryDateCalculator");
    ga.addParam('sysparm_name','isBusinessDayWithHolidaySchedule');
    ga.addParam('sysparm_delivery_type', deliveryType);
    ga.getXML(processResponse);
    function processResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer").toString();
        g_form.setValue('v_campus_printshop_expected_delivery', answer);
       
    }

}

Thanks,
Jyothi