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

Chuck Tomasi
Tera Patron

I was able to do this by setting the default value on the variable to something like this:

javascript:addDays(4);

Then I wrote a script include to do this for me like this:

function addDays(numDays) {
	
	var gdt = new GlideDateTime();
	gdt.addDaysLocalTime(numDays);
	
	return gdt;
}

find_real_file.png(date displayed on 2019-01-29)

This will only add 4 days to the date not 4 business days. 

// 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())




Hi Stewe,

Thanks for the quick reply. 

I'm having a bad week so any help I can get, I appreciate.

Can I do this via an on load catalog client script or as a script include?

This totally works, but I'm not sure how to get the results to display as the default value in my catalog forms date field. Either as default or onLoad.