Useful snippets of code given as examples to help with various scripting needs.
Use this script to add a SOAP endpoint to a Unifi Process. You will need to update the api_name to be the same as the one you set in the Process record.
Sometimes it's necessary to remove the namespaces sent in by other systems to make it easier to handle the payload in ServiceNow. The easiest place to do this is within the Scripted SOAP Service, but bear in mind that your payloads will no longer be identical to what the other system sent you. This example shows you how:
Use this script to add a REST endpoint to a Unifi Process. You will need to update the api_name to be the same as the one you set in the Process record.
By wrapping the code in console, we give context to Activity Log and prevent multiple database updates.
This script shows how to find a bond based on an external reference and store some data.
Here you will find a description of the variables that are available to you when scripting in Unifi.
The Add Note Script is used to notify the end user about integration events. These notes are automatically added during processing and the script allows the target of the note to be customised. E.g., notes are usually added to work notes on Task-based tables, but a custom table might have a different field for this.
The Identify Message Script is executed when an inbound request is received. It returns the name of the message that should be used to process the request. Typically, message names are embedded within the request payload, but it's possible to use the other variables available for more complex identification.
The Endpoint URL will be prepended to Message Path values (providing they do not override). Inline scripts using curly braces {}
can be used to construct more advanced endpoints.
We recommend dynamic endpoints only be considered for the same environment. New environments should have new connections so they can be managed more easily.
The Advanced condition is used to script complex trigger logic into the message. Only use this if you cannot use the Outbound condition filters and the single line Outbound condition.
The Path is used to modify the endpoint for the message. It can be used with inline script evaluation to construct more advanced endpoints. Inline scripts should be wrapped with dollar curly braces ${...}
.
The outbound condition is an inline script field useful for simple one-line conditions to be used in conjunction with the filter.
The Reference lookup script is used to extract the internal and external message ID's when an inbound request is received. These ID's are used to locate the bond (and therefore the target) the request applies to.
The XML Template is evaluated in a similar way to a UI Macro and is extremely useful in constructing advanced XML based payloads using Jelly. Other types of payload can be constructed here, however it's normally easier to do this with the Fields and Field Maps or directly in the Message Scripts.
The XML Template will only be evaluated if the payload has not already been set within the Stage to Request message script.
The Source to Stage script is used to capture data from the source record, e.g., an Incident, and save it to the stage record where it is ready to be used to generate a payload.
Source data values should be captured in full (including referenced values) in the Source to Stage script.
The Stage to Request script is used to generate a payload using the data captured on the stage.
Payload generation and request configuration should be done in the Stage to Request script.
The Payload to Stage script is used to capture data from the inbound request payload and save it to the stage record where it is ready to be used to update the target record.
Data should be extracted from the inbound payload and headers in the Payload to Stage script.
The Stage to Target script is used to update the target record, e.g., an Incident, with the data and references given in the stage.
Reference lookups, data validation, and business logic should be done in the Stage to Target script.
The default inbound script can be used so set the default value to be used by the Field Map when no value is found on the stage.
The default outbound script can be used so set the default value to be used by the Field Map when no value is found on the source.
Fields maps are compiled during Build operations with the field as an input and the resulting code is added to the respective Message Scripts.
Only code contained within dollar-square brackets $[...]
will be compiled. During inbound/outbound processing, standard Message Script variables will apply.
The Response Action script is executed when Run Script is checked. It can be used to do anything based on a response to an outbound request.
Poll Processor scripts have the following variables available.
Some useful data values can be fetched from the Poller data store.
e.g. poller.getData("$last_execution_time")
Variable | Type | Description |
---|
Variable | Type | Description |
---|
See parameters for available variables.
See parameters for available variables.
Please refer to .
Variable | Type | Description |
---|
More advanced conditions can be made in the script field.
Variable | Type | Description |
---|
Variable | Type | Description |
---|
Install the for full support of Jelly within XML Templates.
Variable | Type | Description |
---|
Variable | Type | Description |
---|
Variable | Type | Description |
---|
Variable | Type | Description |
---|
Variable | Type | Description |
---|
See for available variables.
See for available variables.
Variable | Type | Description |
---|
Variable | Type | Description |
---|
Variable | Type | Description |
---|
Variable | Type | Description |
---|
Name | Type | Description |
---|
| GlideRecord | The target record to update, e.g. an Incident record. |
| String | The update message. |
| Object | An object containing specific properties depending on the note being added. |
| String | The name of the integration. |
| GlideRecord | The Only provided with response action notification. |
| String | The type of note: Only provided with Bond specific notes. |
| Object | Object used to contain Connection Variables. |
| Object | Object containing several functions that can be used for logging. |
| String | The error message to return from the script. Alternatively you can simply throw a |
| Any | The payload string or object. Pre-processing can be configured on the Integration to automatically convert JSON to |
| Object | An object containing the request headers. |
| Object | A key-value pair object of URL parameters. |
| GlideRecord | The |
| GlideRecord | The |
| Object | Object used to contain Connection Variables. |
| Object | Object containing several functions that can be used for logging. |
| String | The error message to return from the script. Alternatively you can simply throw a |
| Any | The payload string or object. Pre-processing can be configured on the Integration to automatically convert JSON to |
| Object | An object containing the request headers. |
| GlideRecord | The |
| GlideRecord | The |
| Object | The dynamic stage which is automatically stored on the stage record. |
| GlideRecord | The current |
| Object | Instance of Unifi Bond class. |
| GlideRecord | The record of the |
| Object | An object that can be used to pass variables between scripts. |
| Object | Object containing several functions that can be used for logging. |
| String | The error message to return from the script. Alternatively you can simply throw a |
| GlideRecord | The record that triggers the message. The actual table will differ between Processes. |
| GlideRecord | The record of the |
| Object | Object used to contain Connection Variables. |
| Object | Object containing several functions that can be used for logging. |
| String | The error message to return from the script. Alternatively you can simply throw a |
| Any | The payload string or object. Pre-processing can be configured on the Integration to automatically convert JSON to |
| GlideRecord | The record of the |
| Any | The result of the script being called. |
| GlideRecord | The record that triggers the message. The actual table will differ between Processes. |
| GlideRecord | The record of the |
| Object | Object used to contain Connection Variables. |
| Object | Object containing several functions that can be used for logging. |
| String | The error message to return from the script. Alternatively you can simply throw a |
| Any | The payload string or object. Pre-processing can be configured on the Integration to automatically convert JSON to |
| Object | An object containing the request headers. |
| GlideRecord | The |
| GlideRecord | The |
| Object | The dynamic stage which is automatically stored on the stage record. |
| GlideRecord | The current |
| Object | Instance of Unifi Bond class. |
| GlideRecord | The record of the |
| Object | An object that can be used to pass variables between scripts. |
| Object | Object containing several functions that can be used for logging. |
| String | The error message to return from the script. Alternatively you can simply throw a |
| GlideRecord | The record that is being integrated. |
| GlideRecord | The record of the |
| Object | The dynamic stage object. |
| GlideRecord | The record of the |
| Object | Instance of Unifi Bond class. |
| GlideRecord | The record of the |
| Object | Object used to contain Connection Variables. |
| Object | Object containing several functions that can be used for logging. |
| String | The error message to return from the script. Alternatively you can simply throw a |
| Any | The payload string or object. Pre-processing can be configured on the Integration to automatically convert JSON to |
| Object | An object containing the request headers. |
| Object | An object containing the request URL query parameters. This object is compiled and automatically added to the search query of the URL. |
| GlideRecord | The |
| GlideRecord | The |
| Object | The dynamic stage which is automatically stored on the stage record. |
| GlideRecord | The current |
| Object | Instance of Unifi Bond class. |
| GlideRecord | The record of the |
| Object | An object that can be used to pass variables between scripts. |
| Object | Object containing several functions that can be used for logging. |
| String | The error message to return from the script. Alternatively you can simply throw a |
| Any | The payload string or object. Pre-processing can be configured on the Integration to automatically convert JSON to |
| Object | An object containing request headers keyed by header name. |
| Object | An object containing the request URL query parameters. |
| GlideRecord | The |
| GlideRecord | The |
| Object | The dynamic stage which is automatically stored on the stage record. |
| GlideRecord | The current |
| GlideRecord | The record of the |
| Object | Object used to contain Connection Variables. |
| Object | Object containing several functions that can be used for logging. |
| String | The error message to return from the script. Alternatively you can simply throw a |
| GlideRecord | The record that is being integrated. |
| GlideRecord | The record of the |
| Object | The dynamic stage object. |
| GlideRecord | The record of the |
| Object | Instance of Unifi Bond class. |
| GlideRecord | The record of the |
| Object | Object used to contain Connection Variables. |
| Object | Object containing several functions that can be used for logging. |
| String | The error message to return from the script. Alternatively you can simply throw a |
| GlideRecord | The record of the |
| Any | This is the value defined by the Field in its Default Inbound and Default Outbound scripts. It applies only to Source to Stage (Outbound) and Stage to Target (Inbound) scripts. |
| GlideRecord | The current |
| Object | Instance of Unifi Bond class. |
| GlideRecord | The record of the |
| GlideRecord | The record of the |
| GlideRecord | The record of the |
headers | Object | An object containing the request headers. |
query | Object | An object containing the request query parameters. |
| String | The response |
| Object | An object containing response headers. |
| Any | A pre-processed payload string or object. |
| GlideRecord | The record of the |
| Object | Object containing several functions that can be used for logging. |
| GlideRecord | The record of the |
| GlideRecord | The current |
| Connection | An instance of the Connection object that is being used. |
| Object | An object that allows values to be passed between poll processor scripts. |
| GlideRecord | The Poll Request |
| Poller | An instance of the Poller object that is being used. |
| Object | Object used to contain Connection Variables. |
| Object | Object containing several functions that can be used for logging. |
| String | The error message to return from the script. Alternatively you can simply throw a |
| Boolean | Set |
| Any | It's possible to set the result of the request script to the |
| Any | The response from the request script. *Response Script only. |
| Integer | The number of times the poller has been executed. |
| Date Time | The last date/time the poller was executed successfully. Use with |
| Date Time | The last date/time the poller was executed, whether successful or not. |