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:45 AM
Hi @Anurag Tripathi,
Thinking about it that might be the better solution. Assuming I would have the number field value on the form loading.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 08:04 AM
Yes it works well and Display BR runs before form load so at the time of Client script the value is there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 07:19 AM
Hi,
The value you read form server side is dependent on the change on client(the choice made on the form, without saving)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 08:00 AM
There is a simple fix for this. There are a bunch of examples in the Client Script table.
I do not know which plugins that you have so do not know which ones I could send a link to that you would have. But the gist of it is set a variable to indicate if the user has clicked submit and then when its false have your onSubmit code run and make the call but return false. Then when the return function runs you can set the var to true and when its true the onSubmit function just returns true and exits so the form will save.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 08:03 AM
You should have this one since its for sys_db_pbject
https://<YOUR_INSTANCE_NAME>.service-now.com/nav_to.do?uri=sys_script_client.do?sys_id=0369d763bf013000421cdc2ecf0739a7