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

Hi Muhammad,

 

I was able to fix it by adding getDisplayValue().

 

Thanks 

Glad you got it working 🙂

Regards,
Muhammad

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.

Hi Praveen,

If you require business days then you can also try using Schedules during calculation

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @praveenKumar2 

 

Could you help with the code if the same should be implemented for 90business days.

 

Thank you.

 

Regards,

Sarvari K