getXMLAnswer vs getXML
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
Hi there,
While working on GlideAjax from the client, the often seen method is using getXML (hopefully not getXMLWait, though that's another topic). I'm actually wondering why?! I prefer using getXMLAnswer. You might ask yourself now, why?! The reason very simple: getXMLAnswer is slightly easier to write
and getXML returns a whole XML Document while getXMLAnswer only returns an Answer which is far more efficient.
Usage
Here is an example of how you would use getXMLAnswer Client-side:
Here is an example of how you would use getXML Client side:
Again, why getXMLAnswer vs getXML
In the above pictures, you might have already noticed: getXMLAnswer returns the Answer and that's it. getXML still the Answer needs to be parsed. getXMLAnswer is far more efficient looking at it this way.
Far more efficient
getXMLAnswer
To make it more visual. Let's open the JavaScript Executor Client-Side (in Chrome: CTRL + SHIFT + J). And execute below code:
var ga = new GlideAjax('callerUtilsAjax');
ga.addParam('sysparm_name', 'getComputer');
ga.addParam('sysparm_caller', g_form.getValue('called_id'));
ga.getXMLAnswer(_handleResponse);
function _handleResponse(answer) {
console.log(answer);
}
If we open the Chrome Console (F12), we would see:
getXML
Now let's perform the same, though for getXML. Execute below code in the JavaScript Executor:
var ga = new GlideAjax('callerUtilsAjax');
ga.addParam('sysparm_name', 'getComputer');
ga.addParam('sysparm_caller', g_form.getValue('called_id'));
ga.getXML(_handleResponse);
function _handleResponse(response) {
console.log(response);
}
If we open the Chrome Console, we would see:
Result
As you can see in above result pictures, getXMLAnswer only retrieves the Answer which we are actually after. getXML retrieves the whole XML document. In most cases, we are not interested in the whole XML document, though only in the Answer.
Using getXMLAnswer, a little bit easier to write, and far more efficient in what is getting returned! So please when working with GlideAjax Client-side, reconsider using getXMLAnswer instead of getXML.
---
And that's it actually. Hope you like it. If any questions or remarks, let me know!
Kind regards,
Mark Roethof
ServiceNow Technical Consultant @ Paphos Group---
https://www.servicenow.com/community/developer-articles/getxmlanswer-vs-getxml/ta-p/2307589
