
- 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 05:07 AM
have you tried with getXMLAnswer() with the callback function.
eg:
var ga = new GlideAjax('my_script_include');
ga.addParam('sysparm_name', 'test');
ga.getXMLAnswer(myCallbackFunction);
function myCallbackFunction() {
return;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 07:12 AM
This will not really work, since it's an onSubmit function - by the time the server responds to the GlideAjax call - the form would already be submitted. getXMLAnswer and getXML are asynchronous, for onSubmit validation from the server synchronous calls are required.