Scripted SOAP web services
Summarize
Summary of Scripted SOAP web services
Scripted SOAP web services in ServiceNow enable administrators to create custom SOAP web services with defined input and output parameters, using JavaScript to perform operations. This feature offers flexibility but is recommended primarily when direct web services or SOAP web service import sets are insufficient, as those alternatives are simpler to implement and maintain.
Show less
Security
Scripted SOAP web services adhere to the same base security options as all SOAP web services. When strict security is enforced, the HTTP authenticated user must have the soapscript role to execute the scripted web service, ensuring controlled access.
WSDL and Compliance
ServiceNow dynamically generates WSDL XML documents for all tables and import sets to describe their schema and operations. For scripted SOAP web services, the generated WSDL reflects the Input and Output Parameters related lists. However, since the script governs the actual SOAP response, output parameters may be returned in a different order than defined in the WSDL.
To enforce the output parameter order to match the WSDL, select the WSDL Compliance checkbox. When enabled, the service reorders output parameters accordingly and excludes any parameters not defined in the Output Parameters related list.
Static WSDL
Some clients require SOAP access through a specific WSDL format that differs from ServiceNow’s standard format. In these cases, ServiceNow allows the creation of a static WSDL tailored to the required format to ensure compatibility.
Global Variables Available in Script Context
- soapRequestDocument: Java object representing the incoming SOAP envelope as a DOM Document.
- soapRequestXML: String representation of the incoming SOAP envelope XML.
- request: JavaScript object with input parameters mapped from the incoming SOAP request.
- response: JavaScript object used to customize the SOAP response output.
Practical Use and Next Steps
- Create new scripted SOAP web services by defining input/output parameters and scripting logic to handle requests and responses.
- Customize SOAP response payloads using the response object for full control over returned XML.
- Create scripted SOAP web services using static WSDLs when specific client requirements dictate a custom WSDL format.
By leveraging scripted SOAP web services, ServiceNow customers can implement complex, customized SOAP integrations while maintaining control over security and response formatting, enabling compatibility with diverse client systems.
Scripted SOAP web services allow a ServiceNow administrator to create custom SOAP web services.
You can define input and output parameters for the SOAP web service and use JavaScript to perform operations. Though this feature is very powerful, use direct web services or SOAP web service import sets whenever possible since they are simpler to implement and maintain.
Security
Scripted SOAP web services have the same base security options as all SOAP web services. For details on SOAP web services security, see SOAP web services security.
When strict security is enforced on a system, the HTTP authenticated user must have the soap_script role to execute the scripted web service.
WSDL
All ServiceNow tables and import sets dynamically generate Web Service Definition Language (WSDL) XML documents that describe its table schema and available operations.
Enforcing WSDL compliance
You can force the response to list output values in the same order as defined in the WSDL.
When you create a scripted SOAP web service, the generated WSDL is based on the Input Parameters and Output Parameters related lists. The actual SOAP response sent by the scripted service is determined by the Script. This behavior can cause the script to return output values in a different order than defined in the WSDL.
| Parameter | Order |
|---|---|
| Param 1 | 200 |
| Param 2 | 300 |
| Param 3 | 100 |
The following is the script that sets values for the defined output parameters. Note that in this example script the parameters are set in a different order than defined in the Output Parameters related list. Also note the additional parameter param4 that is not defined in the related list.
Response.param1 = 1;
Response.param4 = 4;
Response.param3 = 3;
When the WSDL Compliance check box is false, the SOAP response generated by the script is the following:
<response>
<param1>1</param1>
<param4>4</param1>
<param3>3</param1>
</response>
<response>
<param3>3</param1>
<param1>1</param1>
</response>Static WSDL
Some web service clients require SOAP access to your instance through a specific WSDL format. This required format may differ from the standard ServiceNow WSDL format. In these cases you can create a static WSDL that matches the required format.
Global variables
- soapRequestDocument: Java org.w3c.dom.Document object representing the incoming SOAP envelope.
- soapRequestXML: String object representing the incoming SOAP envelope XML.
- request: Javascript object that contains mapped values (mapped to input parameter names) of the incoming SOAP envelope.
- response: Javascript object that allows you to customize the response values. See Customize Response