Data Stores

A Data Store is simply a key-value pair stored in the database that is available to all records in the system.

Usage

Use Data Stores to easily make variables persistent and retrievable.

Data Stores are used primarily in Message Scripts and Poll Processor scripts when you want to get and set functional data that is relevant to the integration but does not belong on the target record.

This is particularly handy in a uni-directional integration where polling the remote system is necessary. You can store data such as:

  • The last time a request was made

  • Identifiers that have been seen before

  • Watermarks

Built-in Examples

All Unifi model objects have data store built in. Calling these methods will read/write data stores on the record the object is representing. Note: not all objects available in Unifi scripts are Unifi model objects.

Storing Strings

Use getData and setData to work with simple string-like data.

// Store the current log count
var log_count = bond.getData('log_count');
bond.setData('log_count', parseInt(log_count, 10) + 1)

Storing Objects

You can also work with objects just as easily by using getDataObject and setDataObject. These functions automatically take care of encoding the object for database storage and decoding it for JavaScript usage again.

// Store the logs that have been seen in an array
var logs_seen = bond.getDataObject('logs_seen'); // [1375, 1399, 1748]
logs_seen.push(2140);
bond.setDataObject('logs_seen', logs_seen);

dataStore API

Data stores can be used with any record in ServiceNow using the Unifi dataStore API. We recommend prefixing dataStore with the Unifi scope x_snd_eb to prevent cross-scope issues, e.g. x_snd_eb.dataStore.get(document, "DomainID").

get(document, key [, default_value])

Get a string value from a data store. The default_value parameter will be returned if no data store exists with the specified key.

x_snd_eb.dataStore.get(current, "MyStr");

getAsObject(document, key [, default_object]) {

Retrieve a data value and parse it as JSON to return an object. The default_object parameter will be returned if no data store exists with the specified key.

x_snd_eb.dataStore.getAsObject(current, "MyObj");

remove(document, key)

Remove a single data store.

x_snd_eb.dataStore.remove(current, "MyStr");

removeAll(document)

Remove all data stores for a document.

x_snd_eb.dataStore.remove(current);

set(document, key, value [, description])

Store a key/value pair against a document. An optional description can be provided for future reference.

x_snd_eb.dataStore.set(current, "MyStr", "My value", "This is my value");

setFromObject(document, key, obj [, description])

Encode an object as JSON and store the value against a document. An optional description can be provided for future reference.

x_snd_eb.dataStore.set(current, "MyObj", {foo: "bar"}, "Hello world!");

Last updated

Was this helpful?