Variables

Here you will find a description of the variables that are available to you when scripting in Unifi.

Integration

Add note script

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.

// An example add note script
function addNote(target, note, options) {
  var message = '[' + options.integration_name + ' Integration] ' + note;
  if (options.type == 'error' || options.type == 'warn') {
    message = '[code]<span style="color: red">' + message + '</span>[/code]';
  }
  target.work_notes = message;
}
VariableTypeDescription

target

GlideRecord

The target record to update, e.g. an Incident record.

note

String

The update message.

options

Object

An object containing specific properties depending on the note being added.

options.integration_name

String

The name of the integration.

[options.response_action]

GlideRecord

The Response Action [x_snd_eb_response_action] record being used.

Only provided with response action notification.

[options.type]

String

The type of note: info or error.

Only provided with Bond specific notes.

variables

Object

Object used to contain Connection Variables.

log,console

Object

Object containing several functions that can be used for logging. info, warn, error and debug.

error

String

The error message to return from the script. Alternatively you can simply throw a string or Error and the system will take care of it.

Identify message script

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.

// An example identify script
function identify() {
  return (payload.message.name || '') + '';
}
VariableTypeDescription

payload

Any

The payload string or object. Pre-processing can be configured on the Integration to automatically convert JSON to Object or XML to XMLDocument2.

headers

Object

An object containing the request headers.

params

Object

A key-value pair object of URL parameters.

integration

GlideRecord

The Integration [x_snd_eb_integration] record.

connection

GlideRecord

The Connection [x_snd_eb_connection] record used to receive the request.

variables

Object

Object used to contain Connection Variables.

log,console

Object

Object containing several functions that can be used for logging. info, warn, error and debug.

error

String

The error message to return from the script. Alternatively you can simply throw a string or Error and the system will take care of it.

Connection

Endpoint URL

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.

See Message Path parameters for available variables.

We recommend dynamic endpoints only be considered for the same environment. New environments should have new connections so they can be managed more easily.

Message

Advanced condition

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.

See Outbound condition parameters for available variables.

Extract attachments script

Please refer to Extracting Attachments.

Path

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 ${...}.

/table/incident/${bond.getValue("external_reference")}
VariableTypeDescription

payload

Any

The payload string or object. Pre-processing can be configured on the Integration to automatically convert JSON to Object or XML to XMLDocument2.

headers

Object

An object containing the request headers.

request

GlideRecord

The HTTP Request [x_snd_eb_http_request] record.

stage

GlideRecord

The Stage [x_snd_eb_stage] record.

$stage

Object

The dynamic stage which is automatically stored on the stage record.

transaction

GlideRecord

The current Transaction [x_snd_eb_transaction] record.

bond

Object

Instance of Unifi Bond class.

message

GlideRecord

The record of the Message being used.

scratchpad

Object

An object that can be used to pass variables between scripts.

log,console

Object

Object containing several functions that can be used for logging. info, warn, error and debug.

error

String

The error message to return from the script. Alternatively you can simply throw a string or Error and the system will take care of it.

Outbound condition

The outbound condition is an inline script field useful for simple one-line conditions to be used in conjunction with the filter.

More advanced conditions can be made in the Advanced condition script field.

current.assignment_group && String(current.assignment_group.u_unifi_integrations).indexOf(message.integration) != -1
VariableTypeDescription

current

GlideRecord

The record that triggers the message. The actual table will differ between Processes.

message

GlideRecord

The record of the Message being used.

variables

Object

Object used to contain Connection Variables.

log,console

Object

Object containing several functions that can be used for logging. info, warn, error and debug.

error

String

The error message to return from the script. Alternatively you can simply throw a string or Error and the system will take care of it.

Reference lookup script

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.

// An example reference lookup script
var answer = {};

answer.getExternalMessageID = function (payload, request) {
  return '' + (payload.message.source_id || '');
};

answer.getInternalMessageID = function (payload, request) {
  return '' + (payload.message.target_id || '');
};
VariableTypeDescription

payload

Any

The payload string or object. Pre-processing can be configured on the Integration to automatically convert JSON to Object or XML to XMLDocument2.

request

GlideRecord

The record of the HTTP Request [x_snd_eb_http_request] being used.

answer

Any

The result of the script being called.

current

GlideRecord

The record that triggers the message. The actual table will differ between Processes.

message

GlideRecord

The record of the Message being used.

variables

Object

Object used to contain Connection Variables.

log,console

Object

Object containing several functions that can be used for logging. info, warn, error and debug.

error

String

The error message to return from the script. Alternatively you can simply throw a string or Error and the system will take care of it.

XML Template

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.

Install the Unifi Global Utility for full support of Jelly within XML Templates.

<!-- An example XML template -->
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g:evaluate jelly="true">
		var transaction = jelly.jvar_transaction;
		var stage = jelly.jvar_stage;
		var message = jelly.jvar_message;
	</g:evaluate>
	<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
		<soapenv:Header />
		<soapenv:Body>
			<MessageName>${HTML:message.message_name}</MessageName>
		</soapenv:Body>
	</soapenv:Envelope>
</j:jelly>	
VariableTypeDescription

payload

Any

The payload string or object. Pre-processing can be configured on the Integration to automatically convert JSON to Object or XML to XMLDocument2.

headers

Object

An object containing the request headers.

request

GlideRecord

The HTTP Request [x_snd_eb_http_request] record.

stage

GlideRecord

The Stage [x_snd_eb_stage] record.

$stage

Object

The dynamic stage which is automatically stored on the stage record.

transaction

GlideRecord

The current Transaction [x_snd_eb_transaction] record.

bond

Object

Instance of Unifi Bond class.

message

GlideRecord

The record of the Message being used.

scratchpad

Object

An object that can be used to pass variables between scripts.

log,console

Object

Object containing several functions that can be used for logging. info, warn, error and debug.

error

String

The error message to return from the script. Alternatively you can simply throw a string or Error and the system will take care of it.

Message Script

Source to Stage (Outbound)

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.

// Example source to stage script (using dynamic stage)
$stage.short_description = '' + source.short_description;
VariableTypeDescription

source

GlideRecord

The record that is being integrated.

stage

GlideRecord

The record of the Stage [x_snd_eb_stage] being used. The actual table will differ between Processes.

$stage

Object

The dynamic stage object.

transaction

GlideRecord

The record of the Transaction [x_snd_eb_transaction] being used.

bond

Object

Instance of Unifi Bond class.

message

GlideRecord

The record of the Message being used.

variables

Object

Object used to contain Connection Variables.

log,console

Object

Object containing several functions that can be used for logging. info, warn, error and debug.

error

String

The error message to return from the script. Alternatively you can simply throw a string or Error and the system will take care of it.

Stage to Request (Outbound)

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.

// Example stage to request script (using dynamic stage)
payload.short_description = $stage.short_description;
VariableTypeDescription

payload

Any

The payload string or object. Pre-processing can be configured on the Integration to automatically convert JSON to Object or XML to XMLDocument2.

headers

Object

An object containing the request headers.

query

Object

An object containing the request URL query parameters. This object is compiled and automatically added to the search query of the URL.

request

GlideRecord

The HTTP Request [x_snd_eb_http_request] record.

stage

GlideRecord

The Stage [x_snd_eb_stage] record.

$stage

Object

The dynamic stage which is automatically stored on the stage record.

transaction

GlideRecord

The current Transaction [x_snd_eb_transaction] record.

bond

Object

Instance of Unifi Bond class.

message

GlideRecord

The record of the Message being used.

scratchpad

Object

An object that can be used to pass variables between scripts.

log,console

Object

Object containing several functions that can be used for logging. info, warn, error and debug.

error

String

The error message to return from the script. Alternatively you can simply throw a string or Error and the system will take care of it.

Payload to Stage (Inbound)

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.

// Example payload to stage script (using dynamic stage)
$stage.short_description = payload.short_description;

Data should be extracted from the inbound payload and headers in the Payload to Stage script.

VariableTypeDescription

payload

Any

The payload string or object. Pre-processing can be configured on the Integration to automatically convert JSON to Object or XML to XMLDocument2.

headers

Object

An object containing request headers keyed by header name.

query

Object

An object containing the request URL query parameters.

request

GlideRecord

The HTTP Request [x_snd_eb_http_request] record.

stage

GlideRecord

The Stage [x_snd_eb_stage] record.

$stage

Object

The dynamic stage which is automatically stored on the stage record.

transaction

GlideRecord

The current Transaction [x_snd_eb_transaction] record.

message

GlideRecord

The record of the Message being used.

variables

Object

Object used to contain Connection Variables.

log,console

Object

Object containing several functions that can be used for logging. info, warn, error and debug.

error

String

The error message to return from the script. Alternatively you can simply throw a string or Error and the system will take care of it.

Stage to Target (Inbound)

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.

// Example stage to target script (using dynamic stage)
target.short_description = $stage.short_description;
VariableTypeDescription

target

GlideRecord

The record that is being integrated.

stage

GlideRecord

The record of the Stage [x_snd_eb_stage] being used. The actual table will differ between Processes.

$stage

Object

The dynamic stage object.

transaction

GlideRecord

The record of the Transaction [x_snd_eb_transaction] being used.

bond

Object

Instance of Unifi Bond class.

message

GlideRecord

The record of the Message being used.

variables

Object

Object used to contain Connection Variables.

log,console

Object

Object containing several functions that can be used for logging. info, warn, error and debug.

error

String

The error message to return from the script. Alternatively you can simply throw a string or Error and the system will take care of it.

Field

Default inbound

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.

See Stage to Target (Inbound) for available variables.

Default outbound

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.

See Source to Stage (Outbound) for available variables.

Field Map

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.

var is_mandatory = $[field.mandatory];

if (is_mandatory && $payload.$[field.property] == undefined) {
  throw 'Mandatory field $[field.property] was not provided';
} else {
  $stage.$[field.element] = $payload.$[field.property];
}
VariableTypeDescription

field

GlideRecord

The record of the Field being compiled.

default_value

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.

Response Action

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.

VariableTypeDescription

action

GlideRecord

The current Response Action [x_snd_eb_response_action] GlideRecord.

bond

Object

Instance of Unifi Bond class.

integration

GlideRecord

The record of the Integration [x_snd_eb_integration] being used.

message

GlideRecord

The record of the Message being used.

request

GlideRecord

The record of the HTTP Request [x_snd_eb_http_request] being used.

headers

Object

An object containing the request headers.

query

Object

An object containing the request query parameters.

response_code

String

The response status_code.

response_headers

Object

An object containing response headers.

response_payload

Any

A pre-processed payload string or object.

transaction

GlideRecord

The record of the Transaction [x_snd_eb_transaction] being used.

log,console

Object

Object containing several functions that can be used for logging. info, warn, error and debug.

Event Action

VariableTypeDescription

current

GlideRecord

The record of the Transaction [x_snd_eb_transaction] that triggered the event.

action

GlideRecord

The current Event Action [x_snd_eb_event_action] GlideRecord.

Poll Processors

Variables

Poll Processor scripts have the following variables available.

VariableTypeDescription

connection

Connection

An instance of the Connection object that is being used.

params

Object

An object that allows values to be passed between poll processor scripts.

poll_request

GlideRecord

The Poll Request [x_snd_eb_poll_request] record being used.

poller

Poller

An instance of the Poller object that is being used.

variables

Object

Object used to contain Connection Variables.

log,console

Object

Object containing several functions that can be used for logging. info, warn, error and debug.

error

String

The error message to return from the script. Alternatively you can simply throw a string or Error and the system will take care of it.

ignore

Boolean

Set ignore=true to prevent the poll processor from running. *Setup Script only.

answer

Any

It's possible to set the result of the request script to the answer variable instead of returning it in the function. This value is empty by default. *Request Script only.

response

Any

The response from the request script. *Response Script only.

Data Store Values

Some useful data values can be fetched from the Poller data store. e.g. poller.getData("$last_execution_time")

NameTypeDescription

$execute_counter

Integer

The number of times the poller has been executed.

$last_completed

Date Time

The last date/time the poller was executed successfully. Use with poller.getlastCompleted() to always get a valid date.

$last_execution_time

Date Time

The last date/time the poller was executed, whether successful or not.

Last updated