When we use getXML over getXMLAnswer ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 11:27 PM
Performance wise and code wise community is suggesting to use getXmlAnswer when we are just depends on answer but most of the cases are same in terms of requirements I have seen.
so in which cases/business scenarios where we are compelled to use getXml over getXmlAnswer??

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 11:38 PM
In ServiceNow, the choice between getXML and getXMLAnswer when working with GlideAjax depends on your specific use case and how you want to process the response from the server.
getXML:
Use Case: When you want to process a detailed XML response and potentially extract multiple pieces of information from it.
Details:
The getXML method fetches the server's response as an XML document. You can parse the XML using JavaScript methods like getElementsByTagName, getAttribute, etc. Useful if the server response contains more complex data structures or multiple values.
getXMLAnswer
Use Case: When you only need a single, simple value (like a string or a number) from the server response.
Details:
The getXMLAnswer method simplifies the process by extracting the answer attribute from the XML response and returning it directly. Avoids the need to parse the XML document manually. Faster and more concise when you're only interested in the answer field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 11:41 PM
Hi @Manikantahere ,
Here is a useful article, I could fetch for your reference:
If you find this helpful, please mark as Correct or Helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 11:45 PM - edited 11-28-2024 11:47 PM
Hello @Manikantahere ,
1. Use getXmlAnswer for Performance or Simplicity (When You Only Need the Answer)
When you are only interested in the final answer or response:
When there’s less need to process or manipulate XML:
Example use case:
If you are querying a service for a specific status or result (like a validation response, a result code, or a success/failure flag), getXmlAnswer would be a good choice because it likely returns just the relevant information, making it faster and simpler for such use cases.
2. Use getXml When You Need Full XML or More Complex Data
When you need the complete XML document:
When you need more complex or hierarchical data:
If you need to retrieve multiple pieces of data or handle more complex structures (such as lists, multiple elements, or conditional logic based on the XML content), getXml is typically a better fit.Example use case:
If you are fetching a full report with multiple sections and items (such as a detailed invoice or a multi-field transaction report), getXml would be appropriate because you need access to the entire XML document to extract all relevant information.
3. Performance guideline:
- Use getXmlAnswer when you know you'll only need the immediate answer or a specific part of the XML.
- Use getXml when the full XML response is required, and you’re prepared to process and extract data from it.
Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.
Thanks and Regards,
Ashish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 11:09 PM - edited 12-07-2024 09:18 PM
Even I can get list of values using getXmlAnswer right?
for example if I want get user information by gliding user table you are saying we use getXml but can't I get user information using getXmlAnswer?
if this is not the scenario where we need to use getXml let me know any good scenario for my understanding?