Change SOAP message activity success variable to reference the SOAP response rather than the HTTP code recieved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2017 02:27 PM
I wasn't really sure how to word this in the question section.
Anyways, what I want to do is change when the SOAP message activity outputs success and failure. By default it appears to just output success as long as it made a connection and got a response. I am making a SOAP call to a 3rd party services API to add new users to our companies organization within that 3rd party services application. The response received from this API call has a variable called responseStatus and responseMsg. I would like to have the activity output success only if the responseStatus variable is Success. Else if it fails I will output the responseMsg stating why it failed.
Is there any way to do this using the SOAP message activity or will I have to run a separate script? If I must use a separate script for the error handling, how do I make that script reference the response received from the SOAP message activity? I am fairly new to ServiceNow and am unsure of how to go about this. Any advice would be much appreciated.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2017 10:33 AM
looking further into the log it is giving this:
XMLDocument.selectSingleNode : Prefix must resolve to a namespace: ns
But I have set true when creating an instance of the XMLDocument class which I thought specified that the document is namespace aware?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2017 11:10 AM
Seems like maybe it's getting confused between the SOAP namespace and the embedded response namespace. It works when I just strip out your response for processing. The XML toolset is limited so this may not be the text book way to accomplish.
var xml = '<?xml version=\'1.0\' encoding=\'UTF-8\'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:addUser_Response xmlns:ns="http://team.webservices.kanban.app.digite.com/"><ns:addUserDetails><ns:loginId>test@email.com</ns:loginId><ns:responseStatus>Failed</ns:responseStatus><ns:responseMsg>1.Role \'re\' is not present in the workspace \'1044284\'. </ns:responseMsg></ns:addUserDetails></ns:addUser_Response></soapenv:Body></soapenv:Envelope>' + '';
xml = /<ns:addUser_Response.*<\/ns:addUser_Response>/.exec(xml) + '';
gs.print(xml);
var responseXML = new XMLDocument(xml, true);
var status = responseXML.getNodeText("//ns:responseStatus");
var respMsg = responseXML.getNodeText("//ns:responseMsg");
gs.print(status);
gs.print(respMsg);
Output:
*** Script: <ns:addUser_Response xmlns:ns="http://team.webservices.kanban.app.digite.com/"><ns:addUserDetails><ns:loginId>test@email.com</ns:loginId><ns:responseStatus>Failed</ns:responseStatus><ns:responseMsg>1.Role 're' is not present in the workspace '1044284'. </ns:responseMsg></ns:addUserDetails></ns:addUser_Response>
*** Script: Failed
*** Script: 1.Role 're' is not present in the workspace '1044284'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2017 08:29 AM
I found a work around to this to be:
var status = responseXML.getNodeText("//*[name()='ns:responseStatus']");
This way I ignore the name space all together. Probably not favored by some but it works.