Add 4 business days to date variable on a catalog item

Jeff316
Kilo Guru

Any solutions I could find on the internet have not worked.

I only get strange behavior and have to delete the variable and create again.

We have a date field on a catalog item.

The default date should be 4 business days in the future.

If anyone is currently doing this, please help.

We only use the portal UI.

Thanks.

 

1 ACCEPTED SOLUTION

did you try replacing

edt.getDate();

with

edt.getDisplayValue();

View solution in original post

19 REPLIES 19

Yes, I was just going to say I tried this and got a good date.

 

javascript:var gdt = new GlideDateTime('');
var dc = new DurationCalculator();
dc.setSchedule('090eecae0a0a0b260077e1dfa71da828'); dc.setStartDateTime(gdt);
dc.calcDuration(4*9*3600);
var edt= new GlideDateTime(dc.getEndDateTime())
edt.getDate();
edt.getDisplayValue();

 

 

I cannot believe this is working !!!!

Thank you dvp. 

I'm over joyed.

I know lots of others who would like to do this.

 

 

You are welcome 🙂

So happy !!!!

I hope you have a really good week now.

 

Currently, I'm using this in the default field.

javascript:var d = new GlideDateTime(); d.setValue(gs.daysAgo(-5)); d.getDisplayValue();

This just adds 5 days to today's date, which works. But I would like to use 5 business days.

 

This script below doesn't work just putting into the default field unless I need to format it a certain way.

Same if I make a script include. Do I call the script include from the default field, or call the script include from catalog client script? I can't turn this into a script include as is, since those 2 "if" lines will error.

I can try the script you gave above in the default field if you think it will work.

// 4 business days
// first day of week MONDAY
var gdt = new GlideDateTime();
var days_to_add = 4
var day_of_the_week = gdt.getDayOfWeekUTC(); //monday will be 0
if(day_of_the_week==2){days_to_add = 7};
if(day_of_the_week>=3){days_to_add = 6};
gdt.addDaysLocalTime(days_to_add);

gs.info(gdt.getDate())