Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

date should not be selected more then 60 days in catalog

BrightJunin
Tera Contributor

Hi All,

variable type is Date/Time [ name : Future date ].

 

Now in catalog form my day should not exceed 60 days, 

example [ today is Apr 17th then user should select date before June 15th ] 

 

please help here, how to achieve this 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@BrightJunin 

create onChange client script on that variable

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var selectedDate = new Date(newValue);

var todayDate = new Date(); // Now
todayDate.setDate(todayDate.getDate() + 60);

if (selectedDate.getTime() > todayDate.getTime()) {
alert("Maximum allowed is 30 Days.");
g_form.setMandatory('variableName');
}

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

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

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron

@BrightJunin 

create onChange client script on that variable

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var selectedDate = new Date(newValue);

var todayDate = new Date(); // Now
todayDate.setDate(todayDate.getDate() + 60);

if (selectedDate.getTime() > todayDate.getTime()) {
alert("Maximum allowed is 30 Days.");
g_form.setMandatory('variableName');
}

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

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