,Restrict user to not submit a page until all client side scripts have executed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 11:14 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 11:49 PM
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.
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 11:57 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 12:06 AM
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.
Thank you
G Ramana Murthy
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 11:53 PM
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
Thank you
G Ramana Murthy
ServiceNow Developer