- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 02:58 AM
I need to set due date in the problem task form based on 5 Business days from the created date.
If it's Saturday (6) or Sunday (7) I need to move the date to Monday. I mean I need to skip the weekends and count only the working days to set the due date.
@Ankur Bawiskar Could you please help me on this ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 05:04 AM
Hi @karunasrikuna ,
go with a business rule with a below script :
var createdDate = new GlideDateTime(current.sys_created_on);
var dueDate = new GlideDateTime();
var businessDaysToAdd = 5;
while (businessDaysToAdd > 0) {
dueDate.addDays(1);
if (dueDate.getDayOfWeek() != 6 && dueDate.getDayOfWeek() != 0) {
businessDaysToAdd--;
}
}
if (dueDate.getDayOfWeek() == 6) {
dueDate.addDays(2); // Move to Monday
} else if (dueDate.getDayOfWeek() == 0) {
dueDate.addDays(1); // Move to Monday
}
current.due_date = dueDate;
current.update();
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 11:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 11:03 PM
remove current.update() from script and retest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 07:49 AM
this link should help you add business days using schedule, please enhance it
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