- 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 04:12 AM
Hi,
Use the below article
https://community.servicenow.com/community?id=community_article&sys_id=a7df32a41b728d50c790ece6b04bcb47
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2022 04:14 AM
Hello,
Can you please try below script
var xmlString = request.body.dataString;
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();
var index = i.indexOf("orderID");
if(index > -1){
var end = i.indexOf("\">", index);
gs.info(i.substring(index+7, end));
}
}
The above one prints the ORDER ID follow the same script but replace payloadID in the script for retrieving the payload id
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 05:21 AM
Hi Mohinth,
Thank you for your response.
The above code is giving orderID as 91 in logs.
Best Regards,
Meenal Gharat
- 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