logo

NJP

Processing Inbound XML - Scoped Application Strategy

Import · Apr 19, 2016 · article

Just doing a quick blog today.

I have been on a few calls lately where developers are trying to process XML from an inbound SOAP/REST request. This scenario is usually done with a scripted SOAP web service or a processor (where the payload is in XML format). If you are doing this in a scoped application you probably have already started noticing some API limitations (that you had access to when working in the global namespace). For examples if you need to support namespaces or need to get a list of all the attributes on a Node - you may start to pull your hair out dealing with XML.

Here is the best strategy you can use and I am declaring this a best practice. Stop working in XML while in ServiceNow. Your first step in receiving XML and having to deal with it in JavaScript should be to convert it to JSON. Work in JSON while in the ServiceNow platform.

There is a scoped application safe function you can make (first thing) that will do this conversion for you:

var obj = gs.xmlToJSON(xmlString);

There is one gotcha / caveat you may have to watch out for following this mindset - this strategy will not work with large XML payloads. Converting the XML into JSON will bring the whole thing into memory which may cause issues.

View original source

https://www.servicenow.com/community/developer-blog/processing-inbound-xml-scoped-application-strategy/ba-p/2284630