Search…
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.
1
// An example add note script
2
function addNote(target, note, options) {
3
var message = '[' + options.integration_name + ' Integration] ' + note;
4
if (options.type == 'error' || options.type == 'warn') {
5
message = '[code]<span style="color: red">' + message + '</span>[/code]';
6
}
7
target.work_notes = message;
8
}
Copied!
Variable
Type
Description
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
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.
1
// An example identify script
2
function identify() {
3
return (payload.message.name || '') + '';
4
}
Copied!
Variable
Type
Description
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
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

Attachments can be extracted from payloads and saved before the payload is saved. This is highly recommended as it saves from storing the attachment itself in the payload on the HTTP Request record.
Attachment data should be extracted, saved as an attachment, and replaced with the attachment sys_id in the format <x-attachment-data sys_id="...">. Unifi will automatically collect the attachment ids, create Bonded Attachments for each of them, and finally move the attachments to the target record.
Streaming is better. Attachments can be streamed into Unifi which bypasses the need for extraction, supports binary file sharing, and also allows for sizes up to 50MB (providing your instance and integration configuration supports this).
This is available for all new integrations from Unifi 3.0. Contact us for information on how to do this with previous versions.
Extract attachments script
Script Include
XML
1
// Example extract attachments script using a Script Include
2
// for extracting Base64 from an XML payload.
3
// We rewrite the payload to pass back to Unifi
4
payload = unifi_util.extractAttachmentsFromXml(payload, request);
Copied!
1
// Example script include extract for extracting Base64 attachment
2
// data from an XML payload.
3
// To be used with a Unifi Extract attachments script.
4
unifi_util.extractAttachmentsFromXml = function extractAttachmentsFromXml(payload, request) {
5
6
// create a new standard XMLDocument so we can rewrite it on the fly
7
var xml_doc = new XMLDocument(payload.toString()),
8
attachment_container;
9
10
function extract(node) {
11
var result = null,
12
name,
13
tag;
14
15
if (node.getNodeName() == 'eb:Attachment') {
16
result = {};
17
forEachNode(node.getChildNodes(), function (attr) {
18
// convert eb:FileName to FileName
19
var name = attr.getNodeName().split(':').pop();
20
if (name == '#text') return;
21
result[name] = '' + attr.getTextContent();
22
if (name == 'Data') {
23
attr.setTextContent(''); // remove the attachment data
24
}
25
});
26
27
// Write the attachment using internal Unifi util
28
//tag = '<x-attachment-data sys_id="abc123" />';
29
tag = x_snd_eb.AttachmentHandler.saveAttachment(
30
request, result.FileName, result.MimeCode, decodeData(result.Data));
31
32
insertPointer(node, tag);
33
}
34
}
35
36
function insertPointer(node, tag) {
37
var id,
38
data;
39
// add the attachment pointer for the processor to pick up
40
data = node.getElementsByTagName('eb:Data');
41
if (data.getLength() &gt; 0) {
42
xml_doc.setCurrent(data.item(0));
43
xml_doc.setCurrent(xml_doc.createElement('x-attachment-data'));
44
id = tag.match(/sys_id="(.+)"/);
45
xml_doc.setAttribute('sys_id', id ? id[1] : 'unknown');
46
}
47
}
48
49
function forEachNode(node_list, fn) {
50
var len = node_list.getLength(),
51
i;
52
for (i = 0; i &lt; len; i++) {
53
fn(node_list.item(i), i);
54
}
55
}
56
57
function decodeData(data) {
58
data = ('' + data).replace(/\s/g, '');
59
if (global.snd_eb_util &amp;&amp; global.snd_eb_util.writeAttachment) {
60
return GlideStringUtil.base64DecodeAsBytes(data);
61
} else {
62
return GlideStringUtil.base64Decode(data);
63
}
64
}
65
66
attachment_container = xml_doc.getElementByTagName('eb:Attachments');
67
if (attachment_container) {
68
forEachNode(attachment_container.getChildNodes(), extract);
69
}
70
71
return xml_doc.toString();
72
};
Copied!
1
<!-- Example attachments payload structure -->
2
<eb:Attachments xmlns:eb="https://sharelogic.com/unifi">
3
<eb:Attachment>
4
<eb:FileName>Hello world.txt</eb:FileName>
5
<eb:MimeCode>text/plain</eb:MimeCode>
6
<eb:Data>SGVsbG8gd29ybGQudHh0</eb:Data>
7
</eb:Attachment>
8
</eb:Attachments>
Copied!
Variable
Type
Description
payload
String|Stream
The raw inbound payload object to process. Attachment data should be removed and replaced with the attachment sys_id in the format "<x-attachment-data sys_id=>
headers
Object
An object containing the request headers.
params
Object
A key-value pair object of URL parameters.
request
GlideRecord
The record of the HTTP Request [x_snd_eb_http_request] being used.
options
Object
An object containing specific properties for processing.
options.is_stream
Boolean
True if the inbound payload is a stream.
log
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.

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 ${...}.
1
/table/incident/${bond.getValue("external_reference")}
Copied!
Variable
Type
Description
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
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.
1
current.assignment_group && String(current.assignment_group.u_unifi_integrations).indexOf(message.integration) != -1
Copied!
Variable
Type
Description
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
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.
1
// An example reference lookup script
2
var answer = {};
3
4
answer.getExternalMessageID = function (payload, request) {
5
return '' + (payload.message.source_id || '');
6
};
7
8
answer.getInternalMessageID = function (payload, request) {
9
return '' + (payload.message.target_id || '');
10
};
Copied!
Variable
Type
Description
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
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.
1
<!-- An example XML template -->
2
<?xml version="1.0" encoding="utf-8" ?>
3
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
4
<g:evaluate jelly="true">
5
var transaction = jelly.jvar_transaction;
6
var stage = jelly.jvar_stage;
7
var message = jelly.jvar_message;
8
</g:evaluate>
9
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
10
<soapenv:Header />
11
<soapenv:Body>
12
<MessageName>${HTML:message.message_name}</MessageName>
13
</soapenv:Body>
14
</soapenv:Envelope>
15
</j:jelly>
Copied!
Variable
Type
Description
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
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.
1
// Example source to stage script (using dynamic stage)
2
$stage.short_description = '' + source.short_description;
Copied!
Variable
Type
Description
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
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.
1
// Example stage to request script (using dynamic stage)
2
payload.short_description = $stage.short_description;
Copied!
Variable
Type
Description
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
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.
1
// Example payload to stage script (using dynamic stage)
2
$stage.short_description = payload.short_description;
Copied!
Data should be extracted from the inbound payload and headers in the Payload to Stage script.
Variable
Type
Description
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.
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
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.
1
// Example stage to target script (using dynamic stage)
2
target.short_description = $stage.short_description;
Copied!
Variable
Type
Description
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
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.
Field Map
Message Script
1
var is_mandatory = $[field.mandatory];
2
3
if (is_mandatory && $payload.$[field.property] == undefined) {
4
throw 'Mandatory field $[field.property] was not provided';
5
} else {
6
$stage.$[field.element] = $payload.$[field.property];
7
}
Copied!
1
var is_mandatory = false;
2
3
if (is_mandatory && $payload.short_description == undefined) {
4
throw 'Mandatory field short_description was not provided';
5
} else {
6
$stage.short_description = $payload.short_description;
7
}
Copied!
Variable
Type
Description
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.
Variable
Type
Description
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.
response_payload
Any
A pre-processed payload string or object.
transaction
GlideRecord
The record of the Transaction [x_snd_eb_transaction] being used.
log
Object
Object containing several functions that can be used for logging. info, warn, error and debug.

Event Action

Variable
Type
Description
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.
Last modified 16d ago