Exclude Weekends and Holidays for Calculate TTR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2024 02:50 PM
Hi,
Iam looking to create a Report which track Time to Resolve Tickets, for this I'm in the process of configuring an Action in flow designer, we already have an action available which calculate the TTR. Looking to exclude Weekends and Hoildays for that. having issue in coding part within the Action. Any help is appreciated.
Attached the current script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2024 02:03 AM
Hi @Niranjan2,
You could try this below code:
(function() {
// Define holidays (populate this array with actual holiday dates)
var holidays = ["2024-01-01", "2024-12-25"]; // Example: New Year's Day, Christmas
// Function to check if a given date is a weekend
function isWeekend(date) {
var day = date.getDay();
return (day === 0 || day === 6); // 0 is Sunday, 6 is Saturday
}
// Function to check if a given date is a holiday
function isHoliday(date) {
var dateString = date.toISOString().split('T')[0]; // Get YYYY-MM-DD format
return holidays.includes(dateString);
}
// Function to calculate business days between two dates excluding weekends and holidays
function calculateBusinessDays(startDate, endDate) {
var days = 0;
var currentDate = new Date(startDate);
while (currentDate <= endDate) {
if (!isWeekend(currentDate) && !isHoliday(currentDate)) {
days++;
}
currentDate.setDate(currentDate.getDate() + 1);
}
return days;
}
// Sample usage
var openedDateTime = new Date("2024-05-20T08:00:00Z"); // Example: Ticket opened date and time
var resolvedDateTime = new Date("2024-05-25T16:00:00Z"); // Example: Ticket resolved date and time
var businessDays = calculateBusinessDays(openedDateTime, resolvedDateTime);
gs.info("Time to Resolve (TTR): " + businessDays + " business days");
})();
Please accept my solution if it works for you.
Thanks
Jitendra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2024 02:24 AM
@Jitendra Diwak1 Thanks for the response, can we use the same script in Flow designer Action script? As we have Inputs and Outputs. also, currently i don't have a list of holidays. so, trying to make use of GlideSchedule.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2024 03:59 AM
Hello @Niranjan2 ,
Below flow action script would help you to exclude weekends using OOTB GlideDateTime API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2024 10:42 AM
Hi @Rajesh_Bhise, Thanks for the reply. I'm looking to Exclude Weekends and Holidays for Calculate TTR.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2024 08:49 PM - edited ‎05-22-2024 08:52 PM
Hello @Niranjan2 ,
Below is the script that considers weekends and Holidays to calculate TTR.
(function execute(inputs, outputs) {
var holidays = ["2024-01-01", "2024-12-25"]; // Example: New Year's Day, Christmas
var createdOn = new GlideDateTime(inputs.Created);
var createdDate = new GlideDate(inputs.Created);
var createdDay = createdOn.getDayOfWeekLocalTime(); // getDayOfWeekLocalTime() - Gets the day of the week stored by the GlideDateTime object, expressed in the user's time zone.
var resolvedAt = new GlideDateTime(inputs.Resolved);
var resolvedDate = new GlideDate(inputs.Resolved);
var resolvedDay = resolvedAt.getDayOfWeekLocalTime();
function isHoliday(date) {
var dateString = date.toISOString().split('T')[0]; // Get YYYY-MM-DD format
return holidays.includes(dateString);
}
if(((createdDay == '6'|| createdDay == '7') || (resolvedDay == '6'|| resolvedDay == '7')) || (isHoliday(createdDate)) || (isHoliday(resolvedDate))){ // 6-Saturday & 7-Sunday
var ttr = '';
}else{
var ttr = GlideDateTime.subtract(createdOn, resolvedAt).getDurationValue();
outputs.time_to_resolve=ttr;
}
})(inputs, outputs);
Please mark this answer to correct and helpful if your query is resolved or some help you gained from my post.
Happy to help you in future.
Thank you,
Rajesh