How to use the syntax of getxmlWait(); I want to replace the getxml(); with getxml() wait but I am getting confused with the syntax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2018 06:12 PM
How to use the syntax of getxmlWait(); I want to replace the getXML(ajaxResponse).; with getXMLWait(). wait but I am getting confused with the syntax.
I know getxml() uses asynchronous call and getXMLWait(). uses synchronous call but all I want is that how shall I replace this code as it has a function call back and in that it checks for various condtions.
Even though if I replace that with getXML I still want it to check conditions.. but nowhere in the community I found the exact code.. Please help to understand as this is very critical requirement for.
In a typical example given below.
It's just an example and not the actual requirement. I just want to understand the how the code should be replaced with getXMLWait().
var ga = new GlideAjax('u_getData');
ga.addParam('sysparm_name','DbExist');
ga.addParam('sysparm_db_name',dbName);
ga.addParam('sysparm_sql_server',sqlServer);
ga.addParam('sysparm_inst',inst);
ga.getXML(ajaxResponse);
function ajaxResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'true') {
alert("Database already exist");
g_form.setValue("u_dbname","");
g_form.setValue("u_environment","");
g_form.setValue("u_server","");
}
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2018 07:16 PM
If you must use getXMLWait, this would be the syntax:
var ga = new GlideAjax('u_getData');
ga.addParam('sysparm_name','DbExist');
ga.addParam('sysparm_db_name',dbName);
ga.addParam('sysparm_sql_server',sqlServer);
ga.addParam('sysparm_inst',inst);
ga.getXMLWait();
answer = ga.getAnswer(); //getAnswer() retrieves the result for you
if(answer == 'true') {
alert("Database already exist");
g_form.setValue("u_dbname","");
g_form.setValue("u_environment","");
g_form.setValue("u_server","");
}
The script would NOT work in either a scoped application or the Service Portal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2018 07:55 PM
Hi Wardeep,
What Jim Coyne, here said is absolutely true. If you are using getXMLWait(), then in order to retrieve your answer/result you will have to call getAnswer().
Please find below link just in case of your reference:
getXML() & getXMLWait()
Please mark my answer as Correct/Helpful in case that helps you.
Thanks