- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2020 06:11 PM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 08:32 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 08:31 AM
Hi Muhammad,
I was able to fix it by adding getDisplayValue().
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 08:38 AM
Glad you got it working 🙂
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 08:32 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 08:34 AM
Hi Praveen,
If you require business days then you can also try using Schedules during calculation
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
07-30-2024 03:54 AM
Could you help with the code if the same should be implemented for 90business days.
Thank you.
Regards,
Sarvari K