Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Holiday schedule in India

mossalexr
Tera Contributor

Hey all, I'm creating 4 holiday schedules for a company based in multiple countries. I have the schedules mostly configured, but wondered what people do for multi-day holidays. Some of these holidays for India specifically include Day after Pongal, Day after Deepavali/Diwali, Bakrid, Onam, and a few more. If any one has any solutions they have implemented in the past or any ideas, that would be awesome. Thanks in advanced!

1 REPLY 1

Riya Verma
Kilo Sage

Hi @mossalexr ,

 

Hope you are doing great.

 

 

 

In order to accommodate multi-day holidays for a company with operations in multiple countries, you can follow a few step:

  1. Configure Holiday Schedules:

    • Create separate holiday schedules for each country using the ServiceNow platform.
    • Assign appropriate dates for the holidays that span multiple days, such as the Day after Pongal, Day after Deepavali/Diwali, Bakrid, Onam, and any other relevant holidays.
  2. Implement Multi-Day Holiday Handling:

    • Use Business Rules and Scripts to handle multi-day holidays  that detects if the holiday falls on a single day or spans multiple days.
    • For multi-day holidays, consider using a loop or date range logic to automatically include the additional days as non-working days in the holiday schedule.
    • Make sure to adjust the work schedule and assign non-working days accordingly to reflect the extended holiday period.

sample  code snippet that demonstrates how you can handle multi-day holidays in ServiceNow:

// Assuming you have a holiday schedule named 'India_Holidays'
var holidaySchedule = new GlideRecord('cmn_schedule');
if (holidaySchedule.get('name', 'India_Holidays')) {
    var holidayStartDate = new GlideDateTime(); // Set the start date of the holiday
    var holidayEndDate = new GlideDateTime();   // Set the end date of the holiday

    // Calculate the duration between the start and end date
    var duration = GlideDateTime.subtract(holidayEndDate, holidayStartDate);

    // Add each day within the duration as non-working day in the holiday schedule
    for (var i = 0; i <= duration.getNumericValue(); i += 86400000) {
        var nonWorkingDay = new GlideDateTime(holidayStartDate);
        nonWorkingDay.add(i);
        nonWorkingDay.setDisplayValue('08:00:00'); // Set the time to mark as non-working day
        nonWorkingDay.setDisplayValue('17:00:00');

        // Add the non-working day to the holiday schedule
        var nonWorkingDayRecord = new GlideRecord('cmn_non_workday');
        nonWorkingDayRecord.initialize();
        nonWorkingDayRecord.schedule = holidaySchedule.sys_id;
        nonWorkingDayRecord.non_workday = nonWorkingDay;
        nonWorkingDayRecord.insert();
    }
}

 

 

Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma