Planned start date cannot be earlier than current date

Suresh36
Tera Expert

I have one requirement, Planned start date cannot be earlier than current date on release record.

I have written the below Onchange client script code, but i am getting the below script error. Please help me on this.

 

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

var devRelease = g_form.getDisplayValue('x_thntm_ntrs_devop_devops_release');
//alert('Dev Release :');
if (devRelease) {

var currentDate = new Date();
var startDate = new Date(g_form.getValue('start_date'));

if (startDate.valueOf() < currentDate.valueOf()) {
g_form.addErrorMessage('Error Message Planned start date cannot be earlier than current date');
g_form.setValue('start_date', oldValue);
return false;

}
}

 

Please find the below error message.

Suresh36_0-1682434775954.png

 

 

 

18 REPLIES 18

Samaksh Wani
Giga Sage
Giga Sage

I think you need to set date variables value outside the if (devrealease) means before it

 

DUGGI
Giga Guru

@Suresh36 

 

Your onChange client script looks mostly fine, but there is a small issue in how you're checking for the 'devRelease' value. Instead of using getDisplayValue, you should use getValue to check if the 'devRelease' field is set.

Here's the corrected script:

 

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

    var devRelease = g_form.getValue('x_thntm_ntrs_devop_devops_release');

    if (devRelease) {
        var currentDate = new Date();
        var startDate = new Date(g_form.getValue('start_date'));

        if (startDate.valueOf() < currentDate.valueOf()) {
            g_form.addErrorMessage('Error Message: Planned start date cannot be earlier than current date');
            g_form.setValue('start_date', oldValue);
            return false;
        }
    }
}

Replace your current onChange client script with this corrected version, and it should work as expected.

Hi,

I have tried with the above code, but it is not enter in to the first if condition that means inside if(devRelease)

Rahul Kumar17
Tera Guru

Hi,

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

  var currentDate = new Date();
  var startDate = new Date(g_form.getValue('start_date'));

  if (startDate.valueOf() < currentDate.valueOf()) {
    g_form.addErrorMessage('Planned start date cannot be earlier than the current date.');
    g_form.setValue('start_date', oldValue);
    return false;
  }
}

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar