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.
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.
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.
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.
remove(document, key)
Remove a single data store.
removeAll(document)
Remove all data stores for a document.
set(document, key, value [, description])
Store a key/value pair against a document. An optional description can be provided for future reference.
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.
Last updated
Was this helpful?