On Submit script is not working as expected

Apoorva D
Tera Contributor

Hi Team,

 

I am trying OnSubmit script to validate Actual Start and Actual End date of the change Task. Actual End date can not be before start date, if we enter start date as 28 and end date as 27 then it should not save the form on submit or save Ui action. But even after providing wrong dates its showing alert and form is getting saved. Logs returns correct value, issue is with saving the form.

it also has on change script for similar logic. Can anyone help on how to resolve this issue.

 

Regards,

Apoorva

4 REPLIES 4

Dnyaneshwaree
Mega Sage

If both on change and onload scripts are active then it might be overlap. Also, Instead of alert messages please add error messages/ field messages and if required to stop submitting the form after error then try by adding abort action. 

If the fields are mandatory then you can clear values of that fields after/ before the error message.

If my solution helps you any way then mark it as accepted and helpful.

Thank You!!

Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!

Dnyaneshwaree Satpute
Tera Guru

Hi Dnyaneshwaree,

 

On Change and Onsubmit are active and i have tried with abort it is not working, Alerts i have added in order to test. On Change has valid messages to display when user enters invalid dates.

 

Regards,

Apoorva

 

Vaishnavi Lathk
Mega Sage
Mega Sage

Hello,

It seems like there might be an issue with how the validation logic is implemented in the onSubmit script. Let's refine the logic to ensure that the form is not saved if the Actual End date is before the Actual Start date.

Here's how you can adjust the onSubmit script to achieve this:

 

function onSubmit() {
    var actualStartDate = g_form.getValue('actual_start');
    var actualEndDate = g_form.getValue('actual_end');

    // Check if Actual End date is before Actual Start date
    if (actualEndDate && actualStartDate && actualEndDate < actualStartDate) {
        // Prevent the form from being submitted
        alert('Actual End date cannot be before Actual Start date.');
        return false; // This prevents the form from being submitted
    }

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

Make sure you replace 'actual_start' and 'actual_end' with the actual field names for the Actual Start and Actual End date fields on your form.

Also, ensure that this script is added as the client script for the onSubmit Client Script of the relevant table.

Regards,

Vaishnavi Lathkar

Hi Vaishnavi,

 

If i take directly from Actual start and Actual end and compares, It works for MM-dd-yyyy for other date format  it freezes UI action (submit,save etc). So i am trying it with GlideAjax('TRCheckDatesAjax') function. 

 

Regards,

Apoorva