SOAP messages
Quick answer
Call SOAP services from the platform: WSDL import, envelopes, authentication and error handling.
Key takeaways
- Generate from WSDL where possible
- Parse responses with XMLDocument2, not regex
- Route internal endpoints through a MID server
- SOAP faults carry useful detail, log them
Creating the message
A SOAP message can be generated from a WSDL, which creates functions for each operation with the envelope prefilled. Variables in the envelope use the ${var} syntax and are supplied at runtime.
Calling it
SOAPMessageV2 mirrors the REST API in shape.
var s = new sn_ws.SOAPMessageV2('AcmeBilling', 'getInvoice');
s.setStringParameterNoEscape('invoiceId', id);
s.setHttpTimeout(20000);
var resp = s.execute();
if (resp.getStatusCode() != 200) {
gs.error('Billing SOAP failed: ' + resp.getErrorMessage());
}
var xml = new XMLDocument2();
xml.parseXML(resp.getBody());Practical notes
SOAP endpoints are usually internal and strict.
- Route through a MID server for internal services
- Namespaces matter, parse with XMLDocument2 rather than string matching
- WS-Security headers are often required, add them in the envelope
- Log the fault string, SOAP faults return detail that plain status codes do not
Want to learn this properly?
Our live, instructor-led ServiceNow Training covers this hands-on, with real projects and a certification path.
Check your understanding
Which class parses a SOAP response body?
- A. JSON.parse
- B. XMLDocument2
- C. GlideXML
- D. SOAPParser
Show answer
B. XMLDocument2
XMLDocument2 handles namespaces and node selection.
What is the fastest way to build the envelope?
- A. Type it manually
- B. Generate the message from the WSDL
- C. Copy from another instance
- D. Use a UI page
Show answer
B. Generate the message from the WSDL
WSDL import creates the functions and envelope structure.
Frequently asked questions
Should new integrations use SOAP?
Only when the provider offers nothing else. REST is simpler to operate and debug.
How do we handle WS-Security?
Add the security header to the envelope and store credentials in a credential record referenced by the message.