Cab Date Validation

siva44
Tera Contributor

Hai to  Everyone,

I have one requirement the CAB date cannot be after planned start date ,I have already wrote the one  onchange client script  but it is properly not working when select the cab date in next month date then it is not working thta is only working on current month.

onchange:

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

   //Type appropriate comment here, and begin script below
   var cab = g_form.getValue('u_cab_date');
   var start=g_form.getValue('start_date');
   var cabDate = new Date(cab);
  // cabDate.setHours(0, 0, 0, 0);
      var startDate = new Date(start);
     // startDate.setHours(0, 0, 0, 0);
    if(cabDate > startDate)
   {
        g_form.addErrorMessage("CAB date can't be after Planned start date");
        g_form.setValue('u_cab_date','');
        // g_form.addInfoMessage('cab>planned start date');
    }
    else if((g_form.getValue('start_date') == '' || g_form.getValue('end_date') == '') && newValue != '') {
        alert('Planned start and End date to be filled');
        g_form.setValue('u_cab_date', '');
    }
   
}
 
Thanks @ Regards,
Siva
3 REPLIES 3

AnveshKumar M
Tera Sage
Tera Sage

Hi @siva44 

 

Try the following onChange client script.

 

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

	var cab_epoch = getDateFromFormat(g_form.getValue('u_cab_date'), g_user_date_time_format);
	var cabDate = new Date(cab_epoch);

	var start_epoch = getDateFromFormat(g_form.getValue('start_date'), g_user_date_time_format);
	var startDate = new Date(start_epoch);

    if (cabDate > startDate) {
        g_form.addErrorMessage("CAB date can't be after Planned start date");
        g_form.setValue('u_cab_date', '');
    } else if ((g_form.getValue('start_date') == '' || g_form.getValue('end_date') == '') && newValue != '') {
        alert('Planned start and End date to be filled');
        g_form.setValue('u_cab_date', '');
    }

}

 

It it is not working, please confirm is your CAB Date field is Date type or Date/Time type.

 

Please mark my answer helpful and accept as solution if it helped 👍✔️

Thanks,
Anvesh

The CAB Date  field type  id Date Type so Your script is not working AnveshKumar

 

Hi @siva44 

 

Try the following script.

 

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

    if (isLoading || newValue === '') {

        return;

    }

 

 var cab_epoch = getDateFromFormat(g_form.getValue('u_cab_date'), g_user_date_format);

 var cabDate = new Date(cab_epoch);

 

 var start_epoch = getDateFromFormat(g_form.getValue('start_date'), g_user_date_time_format);

 var startDate = new Date(start_epoch);

 

    if (cabDate > startDate) {

        g_form.addErrorMessage("CAB date can't be after Planned start date");

        g_form.setValue('u_cab_date', '');

    } else if ((g_form.getValue('start_date') == '' || g_form.getValue('end_date') == '') && newValue != '') {

        alert('Planned start and End date to be filled');

        g_form.setValue('u_cab_date', '');

    }

 

}

 

Please mark my answer helpful and accept as solution if it helped you 👍

Thanks,
Anvesh