
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2018 04:00 AM
Hi,
ga.getXMLWait(); // Not working on the portal, what is the alternative?
What is the alternative for this? It works fine in Service Catalog though.
function onSubmit() {
var ga = new GlideAjax('getData');
ga.addParam('sysparm_name', 'servers');
ga.addParam('sysparm_pool',g_form.getValue('vra_pool'));
ga.getXMLWait(); // Not working on the portal, what is the alternative?
var dup = ga.getAnswer();
if(dup == 'false'){
g_form.showFieldMsg('vra_lbaas_pool', dup, 'error', true);
return false;
}
return true;
}
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2018 04:45 AM
Hey,
Having synchronous calls to the server is a bad practice, as that blocks the user's page until the response is received, which results in bad user experience. A workaround to this would be to create onChange scripts to validate user input when values are entered, rather when submitting the form. You could also enforce input validation with a Before Insert business rule and notify user for invalid input (that makes it to the server) via the display message methods of the gs API.
That being said, if you'd really want a synchronous call to the server onSubmit, a workaround is to build a Scripted REST API that would do the same thing as your client-callable script include (they are doing the same thing basically anyway) and send your requests with the native XMLHttpRequest or any other AJAX library that supports synchronous calls (not GlideAjax). Keep in mind that a lot of those libraries (including the JavaScript native XMLHttpRequest) will get their synchronous methods deprecated in the near future, because, as previously mentioned, synchronous calls are a bad practice that should be avoided and more often than not could be worked-around.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2018 04:03 AM
I'm not aware of any alternative to this onSubmit, your best bet is rewriting the rule to run onChange.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2018 04:45 AM
Hey,
Having synchronous calls to the server is a bad practice, as that blocks the user's page until the response is received, which results in bad user experience. A workaround to this would be to create onChange scripts to validate user input when values are entered, rather when submitting the form. You could also enforce input validation with a Before Insert business rule and notify user for invalid input (that makes it to the server) via the display message methods of the gs API.
That being said, if you'd really want a synchronous call to the server onSubmit, a workaround is to build a Scripted REST API that would do the same thing as your client-callable script include (they are doing the same thing basically anyway) and send your requests with the native XMLHttpRequest or any other AJAX library that supports synchronous calls (not GlideAjax). Keep in mind that a lot of those libraries (including the JavaScript native XMLHttpRequest) will get their synchronous methods deprecated in the near future, because, as previously mentioned, synchronous calls are a bad practice that should be avoided and more often than not could be worked-around.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2018 04:53 AM
Right, you guys rock!! 🙂
I will work on the "onChange" workaround just for the portal for now and as to the deprecated libraries..we'll cross that bridge when we get there 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2018 05:03 AM
You won't have to deal with library deprecation if you use the 'onChange' approach, just make sure your GlideAjax calls are asynchronous (getXML or getXMLAnswer), those should not be altered/ deprecated in the near future 🙂 Good luck!