Saving and Retrieving Data

At its core, tray.io is a platform for passing data from once place to another and interacting with different APIs. Sometimes this is as simple as taking some data from A, and putting it in B. Sometimes things get a little bit more advanced, however, and you'll need Tray to save some data.

Here are some examples of where this can be useful:

  • You wish to create a local variable to store a count of items recorded while iterating through a loop.
    • This requires storing an updated count for each loop iteration locally in the context of the Current Run.
  • You wish to identify and sync records that have been updated since the last sync.
    • This requires storing the most recent sync locally in the context of the Workflow.
  • You wish to mark a record as having been "synced" to another system, ensuring it does not get synced twice.
    • This requires storing a unique ID for the record in the context of the Workflow.
  • You wish to store a data element and use it across multiple workflows.  You realize that re-calculating this data element in another workflow would increase the complexity of that flow and you would prefer to make the initial calculation available universally.
    • This requires storing the variable locally in the context of the Account.

The 'Data Storage' Connector

The "Data Storage" connector allows you to save and retrieve data. It works using a Key-Value store, which means that you can set any type of Value you like, using a unique Key to retrieve it.

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

The data storage connector has two key operations - the ability to "get" and "set" data.


See if a record field has changed

To see if a record field has changed (we'll use Account "type" in Salesforce for this example), you'll need to save a copy of the record each time it updates. 

Every update, compare the account type to the saved type using the boolean condition connector, and if it's changed - then take an action. (In this example we'll send ourselves a Slack message)

Step 1. Create a workflow that gets an Account from Salesforce, including the account type.

Step 2. Get the existing saved version of that account from the data storage connector, using a unique key "account_type_ACCOUNTID". (Note that you'll need to replace the ACCOUNTID with the unique ID of the account)

Step 3. If the saved version of the type is different to the current type, then the account type has changed! 

Step 4. Send a Slack message to let us know something has changed.

Step 5. Save the newly updated account to the data storage.


Mark a record as having been synced

Marking a record has having been "synced" or "processed" is another common use-case. Every time a record is synced, you can save a key indicating that is the case.

Step 1. Create a workflow that gets a record from Salesforce, using a manual trigger.

Step 2. Check in data storage whether the record has already synced, using the key "has_synced_ACCOUNTID" (note that you'll need to replace "ACCOUNTID" with a JSONPath expression to reference the unique ID of the Salesforce record.

Step 3. If the record has not been synced, send a Slack message indicating it has been synced. If not, send a message saying it hasn't.

Step 4. If the record hasn't been synced before, make sure we mark as as synced after sending the Slack message!


Syncing records that have been updated since the last sync

Coming soon! 

Last updated 17th March 2017