How to skip the weekends while setting for due date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2019 09:32 PM
Hi,
I am setting due date based in SLA days and created date i.e. if i am creating a ticket the due date has to be set dynamically based on the SLA days and created date.
I am able to get the due date with the help of client script and script include. But it's counting the weekends as well. I need the due date to exclude weekends and take only the weekdays(5 working days (Monday to Friday)) into count.
REF:: Below the script
Script include:
var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
nowDateTime: function ()
{
var getDate = new GlideDateTime(gs.nowDateTime());
var cat = this.getParameter('sysparm_cat');
var subcat = this.getParameter('sysparm_subcat');
var itm = this.getParameter('sysparm_itm');
var gr = new GlideRecord("u_sla_admin_details");
gr.addQuery("u_category", cat);
gr.addQuery("u_sub_category", subcat);
gr.addQuery("u_item", itm);
gr.addQuery("u_record_type", "ADMIN");
gr.addQuery("u_active", "true");
gr.query();
if(gr.next())
{
var slaResult = (gr.u_ttr * 1 );
var slaCall = "";
if (gr.u_sla_days != "")
{
slaCall = (gr.u_sla_days * 1);
gs.log("slaCall value initially is: " + slaCall);
if(getDate.getDayOfWeekUTC() == 6)
{
gs.log("Ticket created in Saturday");
getDate.addDaysLocalTime(2);
}
else if(getDate.getDayOfWeekUTC() == 7)
{
gs.log("Ticket created in Sunday");
getDate.addDaysLocalTime(1);
}
getDate.addDaysUTC(slaCall);
if(getDate.getDayOfWeekUTC() == 6 )
{
gs.log("DayofWeek is Saturday");
getDate.addDaysLocalTime(2);
}
if(getDate.getDayOfWeekUTC() == 7)
{
gs.log("DayofWeek is Sunday");
if(slaCall >= 5)
{
gs.log("slaCall value is greater then 5: " + slaCall);
getDate.addDaysLocalTime(2);
}
else
{
gs.log("slaCall value is less then 5: " + slaCall);
getDate.addDaysLocalTime(1);
}
}
return getDate;
}
else
{
slaCall = "Not Applicable";
getDate = slaCall;
return getDate;
}
}
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2019 10:05 PM
Hi Hemanth,
Did you check this link?
I have posted an approach there
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
10-29-2019 10:17 PM
Hi Ankur,
Yes i did. But i am not able to exclude weekends. Please find the above screenshot. The due date should not take weekdays into count while calculating. The code that you suggested works only when the due date falls into weekends and then adds 2 for Saturday and 1 for Sunday.
I am trying to add the below code but i am not sure were to place it so that is does not take weekends
var days = 0 ;
while (nd < duedate)
{
if (nd.getDayOfWeek() != 6 && nd.getDayOfWeek() != 7)
//excluding Weekends
{
days++ ;
}
nd.addDays(1);
}
Can you please help me out with this?