Validate past date and current date using client script

sushma9
Tera Contributor

Hi All,

 I am validating the past and current dates  using client scripts. Validation for the past date is working fine but if i take the todays  date its not working properly. Let me know if any changes required in my code. 

Apart from creating script include and on change client scripts and validating with UI Policies  and BR is there other  options to validate  the current date . Please let me know what are the changes to be done in my code to get the expected result.

 

Note : I am new to service now and learning the scripting part

 

Code :

    var td = new Date();
    var rd = new Date(g_form.getValue("u_date_of_reservation"));
    if (td > rd) {
        g_form.addErrorMessage(" You Have Selected the Past Date .Please Select the Future Date For Reservation !!!!")
        g_form.clearValue("u_date_of_reservation");
 
// below part of code is not working  //
    } else if (td = rd) {
        g_form.addInfoMessage(" You Have Selected Todays Date .Please Confirm to create the Reservtaion !!!!")
        return confirm();
    } else{
        g_form.addInfoMessage('Reservation is created successfully !!!');
    }
 
 
Error Message for todays Date :
sushma9_0-1688753354649.png

 

11 REPLIES 11

Try this script:-
var today_date = new Date();
var td = formatDate(today_date, g_user_date_format);
var rd = g_form.getValue('u_date_of_reservation');
if (td > rd) {
g_form.addErrorMessage(" You Have Selected the Past Date .Please Select the Future Date For Reservation !!!!");
g_form.clearValue("u_date_of_reservation");
} else if (td == rd) {
g_form.addInfoMessage(" You Have Selected Todays Date .Please Confirm to create the Reservtaion !!!!")
return confirm();
} else{
g_form.addInfoMessage('Reservation is created successfully !!!');
}
//Type appropriate comment here, and begin script below
}
 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

Regards,

Ranjit

this is actually working