onSubmit Client Script finishing before GlideAjax return value is processed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 07:04 AM
I have a client script which will ultimately decide whether it will return false and display an error message to the user if certain criteria is not met.
It initially just had a client-side check which worked perfectly, but now we need to check a condition server side for an additional check.
The issue I'm running into is that despite the GlideAjax returning the correct value (T/F) and display the error, the client script still finishes and saves the record - feels like the client script is finishing before displaying all the alerts.
Is there a way I can ensure the Client Script waits for all the server side conditions to return before running the last check to see whether it should process the onSubmit?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 07:13 AM
Hi @MBarrott ,
Using GlideAjax in an onSubmit client script can lead to timing issues because the script runs asynchronously. When you call GlideAjax, the submission process may complete before the server response is received, which can lead to unexpected behavior.
It's generally recommended to avoid using GlideAjax in onSubmit unless you're certain that you need to make a server call before the form submission, and you're managing the asynchronous nature properly. Instead, consider:
Using onSubmit to validate data: You can perform checks and validation before allowing the submission to proceed, but avoid waiting for a GlideAjax response.
Hope this help you.
Regards
Moin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 07:27 AM
Hi @Moin Kazi,
I need a response from the server as I'm querying data in another table. I then use the onSubmit to validate the response and act accordingly. Unless there is a better way to do this but I couldn't think of one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 07:33 AM
You can write Onbefore Business Rule and abort the action after validation or proceed further.
Or
You can try Onsubmit script with Synchronous GlideAjax call instead of asynchronous call.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 07:36 AM
If you can , fetch the data when form Loads(Display BR, set it on a scratchpad variable)
Then on your client script just use the data and then take action without glide Ajax.