Outbound SOAP Message - need to dynamically generate the payload

Jon_Jennings
Tera Contributor

I have an integration with an in-house application that, up until now, has relied on sending single field values via a SOAP message. My new requirement is to send the contents of a list collector field. Each entry in the list collector references a record on another table with five values.   Each of these values must be sent for each entry in the list collector. The web service in question has been updated and the SOAP Message Function from the new WSDL produces an envelope that contains the following block:

find_real_file.png

I need to dynamically generate my SOAP payload to contain as many copies of this block as there are entries in the list collector.   Is there a way to accomplish this in ServiceNow or am I limited to the envelope as generated in the SOAP Message Function?

My fallback is to recursively collect all of these values into an array, pass that to the web service as a single value and then require them to parse the array.

Thanks in advance for your help.

Jon

3 REPLIES 3

Mike Allen
Mega Sage

Can you pull the values into an array, then do a for loop through the array, and then call the new SOAPMessage logic in the for loop, creating a separate SOAP call for each item?


Possibly - yes. It would require the webservice to add another function. This current function creates a new record in the in-house app so I'd need a function to update an existing record but that might work out.


One option is you can generate entire SOAP message and use setRequestBody API to set body of soap request instead of relying on soap envelop template.


SOAPMessageV2 API - ServiceNow Wiki



The other option i can think of is modify SOAP envelop template to parameterize entire list and populate list string by your self.


<productClassList>${listValue}</productClassList>



Now in you script, you can iterate over your array of items and create a XML structure with which you can create XML string and call


.setParameter(listValue, <yourXMLString>). This will replace ${listValue} with your string.