Christopher_Mal
ServiceNow Employee
Options
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
04-23-2013
01:45 PM
Not gonna really try and show off anything here - but the documentation for XML API is a bit foggy and I want to share this. I tried to use a few common XML API calls that are a bit of a challenge to find out about.
Lets pretend you get a SOAP response and you want to manually iterate through that response envelope that has this structure:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<ns0:Root xmlns:ns0="http://Schemas.SNResponse_RigData">
<Status>Success</Status>
<RigData>Whatever</RigData>
</ns0:Root>
</s:Body>
</s:Envelope>
Here are a few API calls you will need:
this.fSoapDoc = new XMLDocument(requestXML);
var soapBody = this.fSoapDoc.getNode("/Envelope/Body/Root");
var nodelist = soapBody.getChildNodes();
for (var i=0; i < nodelist.getLength(); i++) {
var kidNode = nodelist.item(i);
if (kidNode.getNodeType() == Packages.org.w3c.dom.Node.ELEMENT_NODE) {
var fieldName = Packages.com.glide.util.XMLUtil.getNodeNameNS(kidNode);
var fieldValue = Packages.com.glide.util.XMLUtil.getAllText(kidNode);
gs.log("FIELD NAME: " + fieldName, "cmaloy");
gs.log("FIELD VALUE: " + fieldValue, "cmaloy");
}
}
This is going to get the name and value of the Status and RigData fields.
In this sample we would print to our log file:
FIELD NAME: Status
FIELD VALUE: Success
FIELD NAME: RigData
FIELD VALUE: Whatever
Of course you can do whatever at this point. If your status is Failure you can notify or update the log (etc.)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.