Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

Catalog Client script Validation Not working for date

Shree Nag
Tera Guru

Hello,

I have a catalog client script that fails to trigger for validation.

Please help me get to the issue.

 

Variable on the catalog : date_of_the_event

Validation : This date should not be later than today.

 

The catalog client script is as follows

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || !newValue) {
        return;
    }

    var today = new Date();
    var yyyy = today.getFullYear();
    var mm = String(today.getMonth() + 1).padStart(2, '0');
    var dd = String(today.getDate()).padStart(2, '0');

    var todayString = yyyy + '-' + mm + '-' + dd;

    if (newValue > todayString) {
        g_form.showErrorBox(
            'date_of_the_event',
            'Date of the event cannot be later than today.'
        );

        g_form.setValue('date_of_the_event', '');
    }
}

 

I have attached screenshot of the catalog client script.

Please let me know what AM I doing wrong here.

 

-Appreciate your help.

 

 

1 ACCEPTED SOLUTION

Shree Nag
Tera Guru

I found a better solution. Use catalog UI policy and used Run script to validate the Dates.

View solution in original post

3 REPLIES 3

Shree Nag
Tera Guru

I have chosen the  type of the date_of_the_event as Date.

Shree Nag
Tera Guru

I found a better solution. Use catalog UI policy and used Run script to validate the Dates.

thomasmahon
Tera Contributor

You could try this:

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue === '') {
      return;
   }
   //Type appropriate comment here, and begin script below
   var today = new Date();
    var yyyy = today.getFullYear();
    var mm = String(today.getMonth() + 1).padStart(2, '0');
    var dd = String(today.getDate()).padStart(2, '0');

    var todayString = yyyy + '-' + mm + '-' + dd;

    if (newValue > todayString) {
        alert('Date of the event cannot be later than today.');
        g_form.setValue('date_of_the_event', '');
    }
}