Catalog Client Script help

huyjor
Tera Contributor

Hello Team

 

I have this simple catalog client script. I don't see any problem with this but I'm not sure why it's not working. Thanks for your help. 
Type: Onchange

variable name: end_date

 

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

    //Start date should not allow past date
    var courseStartDate = new Date(g_form.getValue('start_date')); //get start date selected by the user
    var courseEndDate = new Date(g_form.getValue('end_date')); //get end date selected by the user.

    if (courseEndDate.valueOf() < courseStartDate.valueOf()) {
        g_form.addErrorMessage('The End Date should be after the Start Date');
        g_form.clearValue('courseStartDate');
        return false;

    }
}
4 REPLIES 4

SanjivMeher
Kilo Patron
Kilo Patron

Can you try this?

 

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

    //Start date should not allow past date
    var courseStartDate = new Date(g_form.getValue('start_date')); //get start date selected by the user
    var courseEndDate = new Date(g_form.getValue('end_date')); //get end date selected by the user.

    if (courseEndDate < courseStartDate) {
        g_form.addErrorMessage('The End Date should be after the Start Date');
        g_form.clearValue('end_date');
    }
}

Please mark this response as correct or helpful if it assisted you with your question.

If doesnt wrok, try glideajax. Use Case 4 in below thread should help you.

 

https://www.servicenow.com/community/in-other-news/auto-populating-and-validating-date-fields/ba-p/2...

 


Please mark this response as correct or helpful if it assisted you with your question.

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @huyjor ,

 

Try to log the info and check if your get any response

 

if (courseEndDate < courseStartDate ) {

        g_form.addErrorMessage('The End Date should be after the Start Date');

        g_form.clearValue('courseStartDate');

}

 

You don't have to use .value(), seems like it's a Gpt code ...

 

I hope this helps...


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect

Nope, It's not working. It's weird that my code is working on the platform client script but not on the catalog client script. It makes no sense.