Unable to parse inbound SOAP message using scripted SOAP webservice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2022 07:27 PM
We have built a scripted SOAP webservice to consume inbound SOAP calls from various vendors and create incidents in our instance. Each vendor have a different tool/application to connect our instance. We designed our webservice to consume a common payload with identifiers. The payload will contain name value pairs to receive the inbound values from vendor.
we are using the OOB script include - XMLHelper and toObject method to parse the payload. This method needs the exact value of tag to fetch the object.
Current payload:
<soap:Body>
<urn:Tag1>
<urn:request>
............................
</urn:request>
</urn:Tag2>
</soap:Body>
Parsing script:
var helper = new XMLHelper(xmlString);
var obj = helper.toObject();
var obj1 = obj['soap:Body']['urn:Tag1'];
Is there any way we can parse using just ":Body>" instead of "<Soap:Body>" and ":Tag1>" instead of "<urn:Tag1>" (as a few examples), to eliminate the dependency on the namespaces? or even just "Body>" and "Tag1>", so if they use a default namespace, the colon (:) isn't even required...?
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2022 07:45 PM
Hi,
you will have to know the text to be used while parsing.
why not convert that XML to JSON and then use JSON parser
Something like this
var xmlStr = '<soap:Body><urn:Tag1><urn:request>Hello</urn:request></urn:Tag1></soap:Body>';
var jsonObj = gs.xmlToJSON(xmlStr);
gs.info(JSON.stringify(jsonObj));
var request = jsonObj['soap:Body']['urn:Tag1']['urn:request'];
gs.info(request);
Output:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 08:12 AM
Hi Ankur
thanks for your response.
For both cases - parsing as XML or Json , we would need to provide the exact tag name with the namespace [urn:Tag1] . Our ask is probably to remove the namespace and parse using the tag name alone [Tag].
do we have any option for this requirement. The reason is , different vendors are using different namespaces and we are unable to have a common parsing script for all payloads with different namespaces.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2022 08:28 PM
Hi,
I am not sure if namespace can be removed
still check this
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2022 06:49 PM
Hi @Vigneshwaran3 ,
Did you got solution for your issue, I am working on similar requirement to parse without name spaces