Unable to read tran:payload / raw SOAP body in Inbound Scripted SOAP Web Service

ShoelM
Tera Contributor
I am working on an Inbound Scripted SOAP Web Service in ServiceNow, where the incoming request is a SOAP 1.1 message sent from an external system (tested via Postman as well). The SOAP body contains a complex payload wrapped inside multiple namespaces, specifically under tran:ProcessMessage → tran:payload → tran:content, and the actual business XML (star:ProcessRepairOrder) is nested inside this transport envelope. Due to integration constraints, the incoming SOAP XML structure cannot be modified by the source system, and the integration must remain SOAP‑based (Scripted REST or changing the message format is not an option). The challenge I am facing is that, within the Scripted SOAP service, I am not able to read the SOAP body or access the XML inside <tran:payload>, even though the message is well‑formed and reaches the ServiceNow endpoint successfully.
Below is the sample XML:-

<tran:ProcessMessage>
  <tran:payload>
    <tran:content id="A0">
      <star:ProcessRepairOrder>
        ...
      </star:ProcessRepairOrder>
    </tran:content>
  </tran:payload>
</tran:ProcessMessage>
4 REPLIES 4

Matthew_13
Kilo Sage

Hey my Friend

 What your running into is a pretty common issue with Scripted SOAP services, and it usually comes down to how ServiceNow handles the raw SOAP body and XML namespaces.

From what I’ve seen, ServiceNow doesn’t reliably expose the nested SOAP body for you to read directly, especially when the payload is wrapped in multiple namespaces like tran and star. Even though the message is well-formed and reaches the endpoint, you still need to manually parse the raw SOAP envelope.

The approach that’s worked for me is:

  • Read the raw request body instead of relying on any mapped body object.

  • Parse it yourself using XMLDocument2.

  • Use namespace-agnostic XPath (for example, local-name()) so you’re not blocked by prefix differences.

That lets you reliably drill down into:
ProcessMessage → payload → content → ProcessRepairOrder, regardless of the actual namespace prefixes.

One other thing I’d double-check is whether the XML inside <tran:content> is truly nested XML (like in your example) or escaped as text. If it’s escaped, you have to extract the text, unescape it, and then parse it again as XML. That’s a very common transport pattern and will make it look like the node “doesn’t exist” if you try to XPath directly to it.

Bottom line: this isn’t a SOAP 1.1 issue or a Postman issue — it’s just that Scripted SOAP doesn’t do namespace resolution or deep payload parsing for you. Once you grab the raw body and use namespace-agnostic parsing, you should be able to access the XML under <tran:payload> without changing the source system or moving away from SOAP.

 

@ShoelM - Please mark Accepted Solution and Thumbs Up 

Thanks for the detailed response and for sharing your experience — really appreciate it.

The blocker I’m hitting (and what I was trying to validate with this post) is that, in an Inbound Scripted SOAP Web Service, I’m not actually able to obtain the raw SOAP envelope in the first place,
request.getBody(), request.body, request (or similar patterns) consistently returns empty.
So while XMLDocument2 + local-name() absolutely works once you have the XML string, the challenge is that Scripted SOAP does not seem to provide any supported hook to access the raw SOAP body at runtime.
Is there any way to get this raw XML to the instance?


 

You’re not doing anything wrong. Inbound Scripted SOAP does not expose the raw SOAP envelope at all. By the time your script runs, ServiceNow has already parsed and discarded it so request.body, getBody(), etc. being empty is by design.

There is no supported way to access the raw XML in a Scripted SOAP Web Service.

If you need the full SOAP envelope for namespace-agnostic parsing, dynamic payloads and the practical solution is to use Scripted REST and accept the SOAP XML there. That’s what most teams end up doing.

Bottom line: raw SOAP access = not possible with Scripted SOAP in ServiceNow.

 

@ShoelM - Please mark Accepted Solution and Thumbs Up 

RAKESHK65580086
Tera Contributor

How to get raw XML