- 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-08-2020 06:16 PM
refer to my article which calculates business days. That will help you. I don't see calendar in your code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2020 06:39 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2020 06:29 PM
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
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2020 06:35 PM
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