Add +5 Working Business Day in Workflow Designer [toggle scripting]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2025 06:38 PM
Hi everyone,
I have a question regarding date calculation in my workflow. Right now, I'm using the line addDays(5) in my toggle script to add 5 days to the current date, and it's working as expected. However, the requirement is to add 5 business days, excluding Saturdays and Sundays. Does anyone know help me how to achieve this?
Please refer to the image below for more context. Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2025 07:12 PM - edited ‎06-10-2025 07:15 PM
Hi @ricobuenvia ,
you have to create a new schedule for this( or check if there is already a schedule for weekdays and use it)
var startDate = new GlideDate();
var days = 7;
var dur = new GlideDuration(60 * 60 * 24 * 1000 * days);
var schedule = new GlideSchedule('2e75b979c3c2e250051cb132b401315b');//replace this with your schedule record sysid
var end = schedule.add(startDate, dur);
gs.info(end);
this is the background script used test it in background script and adjust script as per requirement sysid of the schedule should be replaced with your schedule's sysid
gs.info with return statement
Schedule docs
GlideSchedule API docs
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2025 12:47 AM
thanks for this information Kilo Patron. also checking on this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2025 12:49 AM
thanks for this information @Chaitanya ILCR looking into this also
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2025 08:05 PM
if you are only skipping saturday and sunday and not concerned about public holiday then this script should help you, use this in that toggle script section
// Set your start date (GlideDateTime object)
var startDate = new GlideDateTime(); // Replace with your actual start date
var businessDaysToAdd = 5;
var daysAdded = 0;
while (daysAdded < businessDaysToAdd) {
startDate.addDaysUTC(1); // Move to the next day
var dayOfWeek = startDate.getDayOfWeekUTC(); // 1=Monday, 7=Sunday
// Only count Monday (1) to Friday (5)
if (dayOfWeek >= 1 && dayOfWeek <= 5) {
daysAdded++;
}
}
// Result: startDate now holds the new date after adding 5 business days
gs.info('New date after 5 business days: ' + startDate.getValue());
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader