getChildNodeIterator() iteration more than no of entries
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2019 02:39 AM
Hi,
I have request body, where multiple nodes can be there in request body xml. But when I am iterating it using getChildNodeIterator(), it is iterating more times than number of entries parent node has.
In the below scenario, logs occurring 6-7 times, when Request body has only one <x:systemResponse> node.
I even tried replacing the statement var sysResp = xmlDoc.getNode('//x:targetResponse') by var sysResp = xmlDoc.getNode('//x:systemResponse'), but same situation was there.
Request Body XML:
xmlDoc.parseXML(reqXML);
var sysResp = xmlDoc.getNode('//x:targetResponse');
var iter = sysResp.getChildNodeIterator();
while(iter.next()) {
var system=xmlDoc.getNodeText('//x:system');
var type=xmlDoc.getNodeText('//x:type');
var msg=xmlDoc.getNodeText('//x:message');
gs.info("System = "+system+"\nType = "+type+"\nMsg = "+msg);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2019 01:42 AM
Hi Priyanka,
I believe that is because of the namespace prefix i.e. x
May be you can create a script include in global scope and pass the xml string, parse it and return whatever you want. in that way you would be able to achieve
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2019 02:40 AM
Hi Ankur,
Actually we may have multiple <x:systemResponse> nodes, therefore we are applying child node iterator.
and in the loop, if we have 2 child nodes, it can only able to search one and iterate it multiple (6-7) times.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2019 03:22 AM
Hi Priyanka,
The issue is because of namespace, so better way is to handle this using the global scope.
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2019 12:12 AM
Hi Priyanka,
Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader