Client Script

HARSHA GOWDA R
Tera Contributor

function onSubmit() {
var terminationDate = g_form.getValue('actual_end_date');
var extensionDate = g_form.getValue('extension_date');
var currentDate = new Date(); // Get the current date

// Convert terminationDate to Date object for comparison
terminationDate = new Date(terminationDate);

// Check if Termination date is the same as the present date
if (terminationDate.toDateString() === currentDate.toDateString()) {
alert('Termination date cannot be the present date.');
return false;
}

// Check if Extension date is before Termination date.
if (extensionDate <= terminationDate) {
// Prevent the form from being submitted
alert('Extension date cannot be before Termination date.');
return false; // This prevents the form from being submitted
}

// If validation passes, allow the form to be submitted
return true;

}
Termination date should not be present date, it should be future date.Where i am going wrong in this script?

4 REPLIES 4

HrishabhKumar
Kilo Sage

Hi @HARSHA GOWDA R ,

Try this code, I've slightly modified the logic.

function onSubmit() {
    var terminationDate = g_form.getValue('actual_end_date');
    var extensionDate = g_form.getValue('extension_date');
    
    var currentDate = new Date(); // Getting the current date
 
    // Converting terminationDate to Date object for comparison
    terminationDate = new Date(terminationDate);
    extensionDate = new Date(extensionDate);
 
    // Checking if Termination date is the same as the present date or before the present date
    if (terminationDate <= currentDate) {
        alert('Termination date should be a future date.');
        return false;
    }
 
    // Check if Extension date is before Termination date
    if (extensionDate <= terminationDate) {
        // Prevent the form from being submitted
        alert('Extension date cannot be before or on the Termination date.');
        return false; // This prevents the form from being submitted
    }
 
    // If validation passes, allow the form to be submitted
    return true;
}

 

Thanks,

Hope this helps.

If my response proves helpful please mark it helpful and accept it as solution to close this thread.

Hi @HrishabhKumar 
It's not working

Are you able to get the alerts?

Nope