How to exclude 2nd & 4th Saturday & Sunday& the public holidays

nikhitha24
Tera Guru

Hi All,

 

Please help me on the below requirement.

I have created NBD and 2BD relative duration.

NBD-if the incident is raised at any time it should complete next business day at 6.30

2BD-if the incident is raised at any time it should complete 2 business day at 6.30

nikhitha24_0-1691921089230.png

For the above requirement i have created by using script.

var days = 1;
if (calculator.isAfter(calculator.startDateTime, "09:00:00")) {
   days++;
}
calculator.calcRelativeDueDate(calculator.startDateTime, days, "18:30:00");
 

 

nikhitha24_1-1691921447244.png

Now how can i add to exclude 2nd&4th Saturday, Sunday and  public holiday. please help me on this

1 ACCEPTED SOLUTION

SwarnadeepNandy
Mega Sage

Hi Nikitha,

 

To achieve this, you need to use a schedule that defines the working days and hours, as well as the holidays, that you want to exclude from the relative duration. A schedule is a record that specifies the time periods when a process or task can run or is active. You can create a custom schedule or use an existing one that meets your requirements.

Once you have a schedule, you can use the DurationCalculator script include to calculate the due date using the schedule. The DurationCalculator script include provides methods to calculate a due date based on a simple duration or a relative duration. You can use the setSchedule() method to specify the schedule and the timezone that you want to use for the calculation. Then, you can use the calcRelativeDuration() method to calculate the due date based on a relative duration record.

Here is an example of how you can modify your script to use a schedule and a relative duration:

// Create a DurationCalculator object 
var dc = new DurationCalculator();

// Set the start date and time of the incident 
dc.setStartDateTime(“2021-10-01 10:00:00”);

// Set the schedule and timezone that you want to use 
// Replace the sys_id with your custom schedule sys_id 
dc.setSchedule(“08fcd0830a0a0b2600079f56b1adb9a2”, “Asia/Kolkata”);

// Calculate the due date based on a relative duration record 
// Replace the sys_id with your NBD or 2BD relative duration sys_id 
dc.calcRelativeDuration(“3bfa9bd10a0a0b5200c18037fbaa9a2c”);

// Print the due date 
gs.print(dc.getEndDateTime());

Hope this helps.

 

Kind Regards,

Swarnadeep Nandy

View solution in original post

1 REPLY 1

SwarnadeepNandy
Mega Sage

Hi Nikitha,

 

To achieve this, you need to use a schedule that defines the working days and hours, as well as the holidays, that you want to exclude from the relative duration. A schedule is a record that specifies the time periods when a process or task can run or is active. You can create a custom schedule or use an existing one that meets your requirements.

Once you have a schedule, you can use the DurationCalculator script include to calculate the due date using the schedule. The DurationCalculator script include provides methods to calculate a due date based on a simple duration or a relative duration. You can use the setSchedule() method to specify the schedule and the timezone that you want to use for the calculation. Then, you can use the calcRelativeDuration() method to calculate the due date based on a relative duration record.

Here is an example of how you can modify your script to use a schedule and a relative duration:

// Create a DurationCalculator object 
var dc = new DurationCalculator();

// Set the start date and time of the incident 
dc.setStartDateTime(“2021-10-01 10:00:00”);

// Set the schedule and timezone that you want to use 
// Replace the sys_id with your custom schedule sys_id 
dc.setSchedule(“08fcd0830a0a0b2600079f56b1adb9a2”, “Asia/Kolkata”);

// Calculate the due date based on a relative duration record 
// Replace the sys_id with your NBD or 2BD relative duration sys_id 
dc.calcRelativeDuration(“3bfa9bd10a0a0b5200c18037fbaa9a2c”);

// Print the due date 
gs.print(dc.getEndDateTime());

Hope this helps.

 

Kind Regards,

Swarnadeep Nandy