
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
12-21-2019 10:51 PM - edited 08-10-2024 08:15 AM
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!
C |
If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.
Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in? |
Kind regards,
Mark Roethof
ServiceNow Technical Consultant @ Paphos Group
---
- 36,534 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Great Job Mark!!!!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mark,
I have a question. In the change request form There are two assessments. One of them is risk assessment and another one is score assessment. I defined them in the same table. When I used getXMLAnswer for UI Action, response becomes same for both assessments. So I can not progress in order to calculate the assessment point. CAN YOU HELP ABOUT THAT TOPIC?

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Berati,
Not sure what you mean here. Can you open a new community question? And paste your question + examples code or screenshots of your situation and the UI Action? Then I can have a look or other Community members will spot your question also and can help/answer your question.
Kind regards,
Mark
---
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
In related list there are two assessment form links.
When I clicked the above, this window opens in the change request
When I click the below, window opens in the change request.
The above works correctly. When I edit the UI action for the second one namely "analysis document notes", res parameter in the getXMLAnswer function returns as DS in other words, in spite of I chose the "analysis document notes", res parameter becomes "fill the risk assessment" XML response.
During the bug, I tried to print "res" parameter. But as a response the DS assessment returns.
Besides, there is a smashing situation for both asessments.
I will be so appreciated for your help...
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mark
Very helpful, thank you! Just one question:
shouldn't the function of your second usage example be called as
_handleResponse(response)
instead of
_handleResponse(answer)
Regards
Patrick

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Patrick,
Actually you could call the parameter anything you want. Only thing, it should be consistent. So if you would call it "abc", then for example:
function _handleResponse(abc) {
console.log(abc);
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Mark
What I was trying to write is that the parameter name in your second example is not consistant as far as I understand.
In the function header you call it "answer" and within the function you reference it as "response".
Or am I wrong here?
Regards
Patrick

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Ah the getXML example? Yes indeed there's a slight error in the image I see 🙂 Also noticiable because response. on the next line is not highlighted blueish. Will make a new image and replace this.
Tnx.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks Mark! I didn't even know getXMLAnswer existed as I always copy and paste the docs example using getXML. Great to squeeze every little bit of efficiency out as we can
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks for sharing @Mark Roethof