Catalog Client Script Date today

Michael Galang
Tera Contributor

Dear Experts, 

I have a catalog client script that is not working. Everytime I select the date today, there is an error, 'The selected date cannot be in the past' and the selected date value always shows the date yesterday when I get the display value.  It should accept the date today regardless of the time and there should be no error message.  I would appreciate your help regarding this matter. 

MichaelGalang_1-1748273377173.png

Here is the client script: 

 

 

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

    var today = new Date();
    today.setHours(0, 0, 0, 0);

    var maxDate = new Date(today);
    maxDate.setDate(today.getDate() + 28);
    maxDate.setHours(0, 0, 0, 0);

    var selected_dateValue = new Date(newValue);
    selected_dateValue.setHours(0, 0, 0, 0);
    g_form.addInfoMessage('The selected_dateValue is: ' + selected_dateValue);
    g_form.addInfoMessage('The today time is: ' + today);


    if (selected_dateValue === today) {
        return;
    } else if (selected_dateValue < today) {
        g_form.setValue('target_upgrade_date', '');
        g_form.addErrorMessage('The selected date cannot be in the past.');
    } else if (selected_dateValue > maxDate) {
        g_form.setValue('target_upgrade_date', '');
        g_form.addErrorMessage('The selected date cannot be more than 4 weeks from today.');
    }
}
5 REPLIES 5

Hi Robert, 

This is noted. Thank you for your recommendation. 😀