Client script was not working for date validation?

Ramu6
Tera Contributor

Hi All,

Actually i have created client script for date validation , but  its not working on the form as expected

Please help me on this

Thanks

Ramu

Ramu6_0-1697121280771.png

 

 

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@Ramu6 

update the if statement as this

if(checkEnd.getTime() < startDate.getTime())

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

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

Hi @Ankur Bawiskar 

Thanks for the response, i have updated but still its not working

@Ramu6 

are you getting the alert for the date values?

please share your latest script here and not the screenshot.

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

@Ankur Bawiskar 

its not enter into if statement , other alert two alert statements are working, and date values are not populating correctly.

 

 

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

    var startDate = new Date(g_form.getValue('u_deduction_start_date'));
    var checkEnd = new Date(g_form.getValue('u_deduction_end_date'));
    alert('end date:'+checkEnd);
    if (checkEnd.getTime()<startDate.getTime()) {
        alert('Deduction End date must be after Deduction start date.');
        g_form.setValue('u_deduction_end_date', '');



        //Type appropriate comment here, and begin script below

    }

}