Search…
Snippets
Useful snippets of code given as examples to help with various scripting needs.

Scripted SOAP Service

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.
1
(function scriptedWebServiceOperation(request, response) {
2
3
var helper = new x_snd_eb.SoapHelper('api_name'); // the API name of the Unifi Process
4
var xml = helper.processRequest(soapRequestXML);
5
response.soapResponseElement = snd_eb_util.getSoapResponseElement(xml);
6
7
})(request, response);
Copied!

Scripted REST API

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.
1
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
2
3
x_snd_eb.ws_console.execute('Request received', function() {
4
var helper = new x_snd_eb.RestHelper('incident_guide'); // the API name of the Unifi Process
5
processAttachment(helper.getRequest().getRecord());
6
helper.processRequest(request, response, 'POST'); // the HTTP method of the resource
7
});
8
9
})(request, response);
Copied!
By wrapping the code in console, we give context to Activity Log and prevent multiple database updates.

Poll Requests

Bond location and data

This script shows how to find a bond based on an external reference and store some data.
1
var integration = poll_request.$model.getIntegration();
2
var bond = new Bond(integration.getConfig());
3
var external_ref = 'BP-41951';
4
5
try {
6
if (bond.locateReference(integration, '', external_ref, 'external')) {
7
// found bond ... do your processing here
8
9
bond.setData('key', 'abc');
10
bond.setDataObject('key', {foo: 'bar'});
11
12
} else {
13
throw 'Unable to locate bond for reference "' + external_ref + '"';
14
}
15
} catch (e) {
16
log.error(e);
17
}
Copied!
Last modified 8mo ago