XMLHelper with Namespaces

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2014 09:48 AM
ServiceNow Level: Beginner
Trying to parse a SOAP response and I have found all suggestions point to XMLDocument and XMLHelper but I see very little about what functions are exposed through these objects. I think my troubles are due to the namespace in the xml. Here is an example of the xml:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header />
<s:Body>
<CreateIncidentResponse xmlns="http://tempuri.org/">
<CreateIncidentResult xmlns:a="http://schemas.datacontract.org/2004/07/Entities.CMS.ExternalServices"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Messages />
<a:Success>true</a:Success>
<a:TicketID>I140000048</a:TicketID>
</CreateIncidentResult>
</CreateIncidentResponse>
</s:Body>
</s:Envelope>
var response = s.post();
var helper = new XMLHelper(response);
var obj = helper.toObject();
JSUtil.logObject(obj, 'obj Response: ');
Log Object: obj Response: Object @xmlns:s: string =
http://schemas.xmlsoap.org/soap/envelope/ s:Body: Object UpdateIncidentResponse:
Object @xmlns: string = http://tempuri.org/ UpdateIncidentResult: Object
@xmlns:a: string =
http://schemas.datacontract.org/2004/07/Entities.CMS.ExternalServices
a:Success: string = true a:TicketID: string = I140000048 a:Messages: null = null
@xmlns:i: string = http://www.w3.org/2001/XMLSchema-instance
I can see the values (success = true and TicketID = I140000048) in the object but I don't understand how to access those values from code. Since I can't step through the code it is difficult to understand the structure of the object that is created.
Sorry if I'm reposting a question but I haven't found a great example yet.
- AA
- Labels:
-
Integrations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2014 09:51 AM
I would actually prefer using XMLDocument using a generic XPATH like "//TicketID" if possible. I'm thinking the object will contain specific properties like CreateIncidentResult. There are a number of SOAP calls with similar response, I would like to have shared code that goes directly to Success and TicketID.
Thanks again,
AA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2014 03:56 AM
Hi,
Did you find any solution to your issue.
I am facing the same problem. When trying to capture such a response in code (Business Rule that invokes the web service) Response value in the below code statement does not assign any value to into Response.
var Response = s.post();
Thanks
Tanu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2014 03:48 PM
I am also having the same issue. Did you find a solution?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2014 04:13 PM
Hi Ronald / All,
Try using the following syntax:
var ticketId = obj["s:Body"]["CreateIncidentResponse"]["CreateIncidentResult"]["a:TicketID"];
Simple "dot-walking" syntax will not work in this case due to the colons in the element/attribute names.