Open Navigation

Data Storage

Store data and create local variables in Tray
On This Page

Overview

The "Data Storage" connector on Tray allows you to set and get arbitrary data, or perform more complex operations on lists and objects. It works using a key-value store, which means that you can set any type of value you like, using a key to retrieve it. At its core, Data Storage can allow you to work with local variables, easily share data between multiple steps in a custom way, pass data between workflow executions, or even multiple workflows.

Example Usage

You can find an example of this connector being used in Polling for Updates and Saving and Retrieving Data

Getting and Setting

To initialize a data storage key, Set it to a specific value.

To access the value that you have set, you must perform a Get operation.

Think of this as performing a database query. You must first insert the row. Once the row is inserted, you may grab the row and access the data from that row.

Using the Default Value

If the given key is not found then the default value will be returned - which can be set to anything. This is really useful for initialising new lists, strings, or counters that you plan to add things to. For example, now the first Get call for a new key can return an empty list, empty string, or 0, rather than null.

Configuration

Most of the Data Storage operations share the following properties:

OperationDescription
Set Value"Set a value in the chosen scope, under a specified key."
Ex. A: Initialize a counter to zero
Ex. B: Update the value of a counter you initialized earlier in the workflow
Get Value"Get a value set earlier in the chosen scope, under a specified key."
Example: Retrieve the current value of a counter you are using in your workflow.

Key

Unique identifier to reference the location where a value is stored. Use a unique key for each Data Storage element you wish to use, e.g. a single object or a list. You may also use the same key for multiple items, as long as each piece of data is in a different scope.

When working with similar data, consider using a list instead of multiple, single items under different keys.

We recommend using 'snake_case' when creating your key.

Value

Data element to pair with a given key.

For example, you might want to save the last time you ran a "sync" between two systems, like this:

Key: last_sync_time, Value: 017-02-22T22:29:22+00:00

A value can also be a list with multiple elements:

Key: fetched_items, Value: [{"item1":"a"},{"item2":"b"}]

Scope

The namespace and closure convention for Data Storage. You may use a single key once in each scope.

ValueDescription
Current RunAccessible during a single iteration of a workflow
Example: You wish to create a local variable to store a count of items recorded while iterating through a loop.
WorkflowAccessible during all iterations of a single workflow
Example: You wish to record the number of users who have submitted a form using your workflow.
AccountAccessible during all iterations of all workflows associated with a single user account
Example: You wish to assess the volume of API calls that are running through Tray for your organization. You create a single Data Storage element to capture this information for all of your workflows combined

Consider using Current Run unless you specifically need to share data between multiple executions of the workflow or multiple workflows.

Possible Issues

Be aware of possible issues when using Workflow and Account scopes:

  • Data could become inconsistent if multiple executions are concurrently loading, modifying and then saving a value under the same key
  • High rates of data reads or writes are not supported. This can be an issue if you are running many workflow executions in parallel.

Working with lists, aggregating data

While your execution is running, you can use Append to List to store multiple values for later use. You can then get all stored items at the end of your workflow via Get Value.

  1. First, create the list using Set Value or have it created automatically on first append by checking the property 'Create if missing'.
  2. Use Append to List in multiple steps or inside a loop to add more items to the list. You can also append another list.
  3. Once you are finished adding the data, you can use Get Value to load the list.

You can also use Set in List operation to override values under given indices in the list.

Important Note on Advanced Operations

Be aware that the Add to Collection and Shift Collection operations should only be used as a last resort, as they have reliability and performance limitations if used in Workflow or Account scope.

They can be used to implement a queue, but if possible, use the AWS SQS connector instead.

Limitations

  1. A hard limit on a value under a single key is 400 KB. Usually the limit will be slightly lower, depending on the size of metadata kept around the value.
  2. Data storage can store objects up to 32 levels of depth. If you need more deeply-nested objects, use a switch in advanced properties in Set Value operation.
Was this article helpful?
Yes
No
On This Page