Calculating Due Date Based on Requested Date

ljschwaberow
Giga Expert

I've been reviewing the Using DurationCalculator To Calculate a Due Date - ServiceNow Wiki wiki article to figure out how to set the default for a Catalog variable 'Due Date' to three business days from the 'Requested Date' = javascript:gs.now(). I think I need to create a schedule to incorporate in the scripting that is provided in the wiki article but I'm not sure how to design one that defaults to three weekdays from now. I'm still not too comfortable with scripting to but I think that is what I need, does anyone have any advice?

1 ACCEPTED SOLUTION

andrew_venables
ServiceNow Employee
ServiceNow Employee

Sorry Lindsey, not having much luck here!



I've tested this and definitely got it this time...



You just need to add the below as a new line at the top of your script:


javascipt:



So it will look something like:


javascript:


// Get the datetime now


var nowGdt = new GlideDateTime();


...



Fingers crossed!


View solution in original post

12 REPLIES 12

Thanks again for your help - in looking at it a little closer I noticed that the date is working perfectly but the time is calculating 6 hours from the current time - so it's doing it 3 business days and 6 hours from now. Is there a way to get it to do 3 business days but the same time?



find_real_file.png



Here is the schedule I set up:


find_real_file.pngfind_real_file.png


(a year and a half later) You will need to account for the user's timezone.
dueDateGdt.getLocalDate();


dueDateGdt.getLocalTime();


verda
Mega Expert

I noticed, using child schedules for holidays do not work, so add the holidays directly to Schedule Entries as below:

find_real_file.png

   var sl = new someScriptInclude_util();

current.due_date=sl.ReturnDueDate(2,  current.start_date.toString());

 

 

find_real_file.png

This function will use above schedule, skip holidays, weekends, and calculate your due date.