Unable to parse inbound SOAP message using scripted SOAP webservice

Vigneshwaran3
Tera Contributor

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...?

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

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:

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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.

Hi,

I am not sure if namespace can be removed

still check this

https://community.servicenow.com/community?id=community_question&sys_id=7e61d13bdb3ab41039445ac2ca96...

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Vinoth Murugan
Tera Contributor

Hi @Vigneshwaran3 ,

 

Did you got solution for your issue, I am working on similar requirement to parse without name spaces