,Restrict user to not submit a page until all client side scripts have executed

Anubhav24
Mega Sage
Mega Sage

Hi All,

 

I have a form where user is submitting a request and at times if the users internet is slow they are able to submit the page with incorrect data while the client side logic is being executed.

Is there a way to restrict the user to not submit the form until all client side logic has executed.

4 REPLIES 4

AnveshKumar M
Tera Sage
Tera Sage

Hi @Anubhav24 

It would be better to validate using an onSubmit before submitting the form to check whether all the fields have expected values and prevent the form from submitting if it is not.

 

If we could have access to onLoading variable in onSubmit it would have been more easy.

Thanks,
Anvesh

On Submit logic is fine but is there a way to know if all the logic has executed in the backend , thats what i want to know/understand.

The onSubmit() client script in ServiceNow executes synchronously.

onSubmit() client script is executed when a form is submitted.

It runs on the client-side before the form data is submitted to the server.

It is synchronous, meaning it will block the rest of the code from executing until it completes its task.

This synchronous behavior is useful for validation checks or other tasks that need to be completed before the form data is sent to the server.

If the onSubmit() script returns false, the form submission is cancelled.

If it returns true or does not return a value, the form submission continues as normal.

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

RAMANA MURTHY G
Mega Sage
Mega Sage

Hello @Anubhav24 ,

Yes, there is a way to restrict the user from submitting the form until all client-side logic has executed in ServiceNow. This can be achieved by using Client Scripts.

function onSubmit() {
     // Your client-side logic here
     if (/* Your condition here */) {
            // If the condition is not met
            return false;              // This will prevent the form from being submitted
     }
     else{
          // If all conditions are met
       return true; // This will allow the form to be submitted
     }
}

The "onSubmit" client script is executed when the form is submitted.

Returning false from the script will prevent the form from being submitted.

 

 

Please mark my answer correct & helpful, if it helps you

Thank you

 

 

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer