Restrict Date Variable for all Catalog Items to Not allow Past Dates

marrerocmm
Tera Contributor

Hello, I'm trying to create a script or solution that would apply for the date variable type on all catalog items and would restrict users from selecting a date in the past. Does anyone know of a way to do this? Would like for the solution to be applied to the date variable type on all catalog items without having to apply it to each item individually. Thank you in advance!

1 ACCEPTED SOLUTION

Vikas-Malhotra
Mega Guru

Hi @marrerocmm ,

 

You can write a onChange client script on date field to call a client script.

 

In that script include, create a function to check the past date something like this:

function isPastDate() {
var initDate= new GlideDateTime(this.getParameter('YOUR_DATE_PARAMETER'));
var today = new GlideDateTime();
}

if(initDate.compareTo(today)) {
    gs.info('Past date is not allowed')
    return true;
}

 

and in the client script check if the function returns true then, print an error message and return false.

 

 

Hope this helps!

 

Regards

View solution in original post

1 REPLY 1

Vikas-Malhotra
Mega Guru

Hi @marrerocmm ,

 

You can write a onChange client script on date field to call a client script.

 

In that script include, create a function to check the past date something like this:

function isPastDate() {
var initDate= new GlideDateTime(this.getParameter('YOUR_DATE_PARAMETER'));
var today = new GlideDateTime();
}

if(initDate.compareTo(today)) {
    gs.info('Past date is not allowed')
    return true;
}

 

and in the client script check if the function returns true then, print an error message and return false.

 

 

Hope this helps!

 

Regards