- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2022 04:01 AM
Hello all,
Can someone please help me to retrieve attribute value from my xml payload.
below is the example for my xml payload:
Solved! Go to Solution.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2022 05:56 AM
Hello
My bad sorry!
Can you try with below script .It worked for me with your payload
var xmlDoc = new XMLDocument2(xmlString);
xmlDoc.parseXML( xmlString );
var node = xmlDoc.getNode("//ConfirmationRequest");
var childNodes = node.getChildNodeIterator();
while(childNodes.hasNext())
{
var i = childNodes.next().toString();
gs.info('testing xmls'+i);
var index = i.indexOf("orderID");
gs.info('testing index'+index);
if(index > -1){
var end = i.indexOf("\">", index);
gs.info('My values'+i.substring(index+9, end));
}
Please try this and let me know
Proof :
Please mark my answer correct if it helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2022 06:30 AM
you can convert the XML to JSON and then use JSON parser
Parsing JSON is much easier
It worked well for me
var str = gs.getProperty('xml.string');
var jsonObj = gs.xmlToJSON(str);
var orderID = jsonObj.cXML.Request.ConfirmationRequest.OrderReference.orderID;
var payloadID = jsonObj.cXML.Request.ConfirmationRequest.OrderReference.DocumentReference.payloadID;
gs.info("orderID->" + orderID);
gs.info("payloadID->" + payloadID);
Output:
Regards
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
07-16-2022 02:26 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader