Web based applications have traditionally been notorious for having tedious, repetitive user interfaces that have made them difficult to adopt. As the web has evolved, so has the interfaces. ServiceNow has always impressed me on the simplicity of the UI and how it can be used to reduce manual interaction.
It is rare to find a section of the UI that is repetitive and tedious. However, I realized the other day that I was spinning wheels unnecessarily with the UI and a simple fix was available.
The issue lies with the SOAP Message Generator (The REST Message Generator has the same issue, but can be fixed just as easily). When you consume a WSDL, the SOAP Message tool will auto generate all of the available functions as well as a template for the SOAP Envelope. In the SOAP Envelope, ServiceNow intelligently determines elements that may require data for a SOAP submission and it populates those elements with a ${variable_name} string. These are special ${} style variables that can be used to insert dynamic data into your SOAP Message.
So far, so good, right? This is a big help, but there is another step that I felt just got left out. If you want to either test the SOAP message function within the tool, or take advantage of the “Preview script usage” feature to autogenerate sample code for the web service call, you have to first create SOAP Message Parameters for each of the ${} style variables in the envelope.
This is typically ok if you have two or three tag elements that will have dynamic content. However, there are some web services where you could be submitting more than 20 pieces of data.
In order to make this experience a little easier to deal with, you can create a UI Action that will read the SOAP envelope and generate all of the variables for you.
UI Action Details
Name: Generate SOAP Message Parameters
Table: SOAP Message Function [sys_soap_message_function]
Action Name: gen_soap_params
Form Link: Checked
Active: Checked
Show insert: Checked
Show update: Checked
Comments: Read the SOAP Envelope and generate SOAP Message Parameters from all of the ${} variables found in the envelope.
Condition: current.envelope != “”
Script:
1 2 3 4 5 6 7 8 9 10 11 | var variables = current.envelope.match(/\$\{.*?\}/g); for(var key in variables){ var p = new GlideRecord("sys_soap_message_parameters"); p.initialize(); p.name = variables[key].replace(/\$\{/,"").replace(/\}/,""); p.soap_function = current.sys_id; p.insert(); } action.setRedirectURL(current); |
Result
The above picture shows part of a SOAP Envelope that contains 72 variable elements. Normally you would have to create all 72 variables as SOAP Message Parameters. However, with the click of the new “Generate SOAP Message Parameters” UI Action link, those parameters get auto populated for you.
Download the UI Action
Click the following link to download the UI Action record to easily install it into your instance: Auto Generate SOAP Parameters
This is awesome! Also you rocked at K13!
This logic has helped reduce lot of man work in my various soap message parameters creation.
Thanks for sharing this information.
Hi John tried the same way as you have mentioned i am getting the ui action link but the parameters are not inserted.
Awesome! This just saved me a lot of time. Any reason why this wouldn’t just automatically be invoked from the ‘Generate sample SOAP messages’ UI action on the SOAP message record? That would allow you to generate functions and parameters all in one click.
@Mark – very true…would be extremely convenient. The only reason I didn’t do this was so that I didn’t modify any out of the box UI Action. This way, adopters of the update set can feel confident that they will still receive all upgrades and enhancements to this part of the product.
Hi John, Is there any way making soap call from a dynamic block?
HI John,
We are trying to integrate our monitoring tool with snow for auto incident creation. As part of this we wan to pass soap call to snow from a perl script. Any leads would be helpful on how the format of SOAP call should be if possible a sample code. Thanks