Adding 3 business days from last working date variable to due date

praveenKumar2
Kilo Expert

Good Evening All,

I am having hard time adding 3 business days from last working date to due date.

There is a variable called Last working date and using a workflow script i need to add 3 business days to the last working date and append it to the due date field on the RITM. 

I have used 


var gdt = new GlideDateTime(termDate);
//gdt.addDays(3);
gdt.addDaysLocalTime(3);
//gs.print(gdt.getDate());
gs.print(gdt.getLocalDate());
current.due_date = gdt.getLocalDate(); 

But it only is adding 3 consecutive days and time is not being updated. 

Then i tried 

var gdt = new GlideDateTime(termDate);
if(gdt.getDayOfWeekLocalTime() == 3)
gdt.addDaysLocalTime(5);
else if(gdt.getDayOfWeekLocalTime() == 7)
gdt.addDaysLocalTime(3);
else
gdt.addDaysLocalTime(3);

current.due_date = gdt.getDisplayValue(); 

Which also is not working as it is supposed to. 

Can anyone provide me how to achieve it? DateTime functionality is little tricky for me to understand. 

So if i select "07-08-2020 17:47:15" the due date should be updated as "07-13-2020 17:47:15"

Thanks in Advance 🙂

pK

 

 

1 ACCEPTED SOLUTION

praveenKumar2
Kilo Expert

Thank you Muhammad and Mike for your help:

Here is the code that is working as i wanted to. 

var gdt = new GlideDateTime(termDate); //

if(gdt.getDayOfWeekLocalTime() == 3)
gdt.addDaysLocalTime(5);
else if(gdt.getDayOfWeekLocalTime() == 4)
gdt.addDaysLocalTime(5);
else if(gdt.getDayOfWeekLocalTime() == 5)
gdt.addDaysLocalTime(5);
else
gdt.addDaysLocalTime(3);

current.setValue('due_date',gdt);

workflow.scratchpad.dueDate = gdt.getDisplayValue();

 

Thanks,

pK.

View solution in original post

14 REPLIES 14

Mike Patel
Tera Sage

refer to my article which calculates business days. That will help you. I don't see calendar in your code.

https://community.servicenow.com/community?id=community_article&sys_id=9c5922aadb597b0cfff8a345ca961...

Thank you Mike for the quick response. 

I have gone through the article but it doesn't meet my need to add 3 business days. 

Your script is adding the duration globally, I just wanted for a single catalog request, where when a user selects a last working date i need 3 business date and time to be added to it. 

Thanks,

Praveen.

MrMuhammad
Giga Sage

try this.

var gdt = new GlideDateTime("07-08-2020 17:47:15"); //

if(gdt.getDayOfWeekLocalTime() == 3)
 gdt.addDaysLocalTime(5);
else if(gdt.getDayOfWeekLocalTime() == 7)
 gdt.addDaysLocalTime(3);
else if(gdt.getDayOfWeekLocalTime() == 6)
 gdt.addDaysLocalTime(4); 
else
 gdt.addDaysLocalTime(3);

//current.due_date = gdt;

gs.info(gdt);

OUTPUT

find_real_file.png

Regards,
Muhammad

Hi Muhammad,

 

Thanks for the response, But i am not looking for a single time i need it calculating dynamically. It should capture the value from the last working date variable and add 3 business days to it. 

I just gave the example of what i wanted to see. 

Thanks,

pK