- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2019 09:50 AM
Hi,
I need to set due date based on working days only(5 working days)
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 resolve an incident to set the due date.
I have written a business rule:
REF::
var days = 0 ;
var createdDate = new GlideDateTime(current.sys_created_on);
gs.log("createdDate is: " + createdDate);
var getSlaDays = current.u_sla_days;
gs.log("getSlaDays is: " + getSlaDays);
var dueDate;
var splitSlaDays = getSlaDays.split(" ");
gs.log("splitSlaDays is: " + splitSlaDays);
var daysValue = splitSlaDays[0];
gs.log("daysValue is: " + daysValue);
//dueDate = createdDate + daysValue;
//dueDate = createdDate.addDaysUTC(daysValue);
if(createdDate.getDayOfWeek() != 6 && createdDate.getDayOfWeek() != 7)
{ //exclude weekends
days++;
gs.log("days is: " + days);
}
createdDate.addDays(1) ;
createdDate.addDaysUTC(daysValue);
gs.log("createdDate is: " + createdDate);
dueDate = createdDate + days;
gs.log("dueDate increment is: " + dueDate);
if( dueDate.getDayOfWeek() == 6)
{
dueDate = dueDate + 2 ;
gs.log("Inside if 6: " + dueDate);
}
if ( dueDate.getDayOfWeek() == 7)
{
dueDate = dueDate + 1 ;
gs.log("Inside if 7: " + dueDate);
}
gs.log("current.u_due_date is : " + dueDate);
current.u_due_date = dueDate;
If the sladays is 2 days to resolve a ticket and the ticket is created on 24/10/19 i need to get the output as 28/10/19 to be set on the due date.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2019 10:42 AM
Hi Hemanth,
So after days from daysValue to the created date if the day is saturday or weekend then get the coming monday as the date?
use below script
var createdDate = new GlideDateTime(current.sys_created_on);
gs.log("createdDate is: " + createdDate);
var getSlaDays = current.u_sla_days;
gs.log("getSlaDays is: " + getSlaDays);
var dueDate;
var splitSlaDays = getSlaDays.split(" ");
gs.log("splitSlaDays is: " + splitSlaDays);
var daysValue = splitSlaDays[0];
gs.log("daysValue is: " + daysValue);
// add days to created date
createdDate.addDaysUTC(daysValue);
// if after adding days it comes as saturday i.e. day as 6 so add 2 days so that it comes to Monday
// if after adding days it comes as sunday i.e. day as 7 add 1 day so that it comes to Monday
if(createdDate.getDayOfWeekUTC() == 6)
createdDate.addDaysLocalTime(2);
else if(createdDate.getDayOfWeekUTC() == 7)
createdDate.addDaysLocalTime(1);
current.u_due_date = createdDate;
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2021 04:26 AM
Hope you are doing good.
Let me know if I have answered your question.
If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2020 07:16 AM
Hope you are doing good.
Let me know if I have answered your question.
If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2019 12:52 PM
I'd tackle this in flow designer by adding a relative duration, as you can attach a schedule to make sure you're targetting only working days.
In the original solution you've posed, it's not going to take into account any public holidays etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2020 09:50 PM
Hi,
If there is any requirement related to working day/hours/bank holiday, I think you should consider to use schedule to calculate.
GlideSchedule & GlideDuration API.