Using Data with Formulas

Formulas are all about referencing and transforming data. Let’s see where that data can come from.

From upstream actions’ events 

Say we’re evaluating a formula's expression in Action B, which is downstream from Action A. Perhaps Action A had fetched a list of users from a remote API.

Now, Action B can make a reference to that data – for instance to count it:

COUNT(action_a.body.collections.users)

Simply refer to the snake cased name of the upstream action to access its data.

From Resources 

Use the special RESOURCE key to access data residing in resources. Let’s say we have a text resource "Domain name". The following expression would fetch it:

RESOURCE.domain_name

From Credentials 

The CREDENTIALS key works identically to the previous example, for fetching credential tokens. (Note: because these are inherently sensitive, we’ll never output a preview value in the formula builder when working with credentials.)

CREDENTIAL.example_api_key

Metadata 

The META key exposes a useful set of information about the current environment. Here’s the full data structure it generates:

"tenant": {
  "domain": "example.tines.com",
  "name": "example"
},
"team": {
  "id": 123,
  "name": "Example team"
},
"story": {
  "id": 123,
  "name": "Example story",
  "key": "example_story",
  "is_test": false
},
"action": {
  "id": 123,
  "name": "Example action",
  "key": "example_action"
},
"story_run": {
  "id": "fc7b6392-b602-465b-8f58-ee07d33fa80e",
  "user_link": "https://example.tines.com/story_runs/fc7b6392-b602-465b-8f58-ee07d33fa80e"
}

So, for example, to access the name of the current story, you could use:

META.story.name

Formula Data Types 

The formula language has the following types, which correspond to the types in standard JSON:

Text 

To enter text, you can wrap your values in either single or double quotes

# Double quotes 
"this is some text" 

# Single quotes 
'this is also some text'

There is no difference in behavior between the quote styles.

If you need to use a quote inside some text you can escape it with \

# Escaping text 
"As Einstein said \"Never memorize something that you can look up.\""

TRUE/FALSE 

Booleans can be accessed like so, note they are case sensitive:

# true TRUE 

# false FALSE

Formulas does not support type coercing, ie. [] will not be coerced to FALSE. All values are truthy by default except for FALSE & NULL.

NULL 

Null values are written in all caps and are falsy:

NULL 

# true IS_BLANK(NULL)

Numbers 

Numbers are written in simple notation.

# number 
123 

# decimal 
123.45 

# negative 
-123

Arrays 

Usually, you will interact with arrays that come from your event data, however, you can also create an array using the array function.

# creating an array 
ARRAY(1, 2, 3) 

# [1, 2, 3]

To access an item in an array, you use square brackets and numbers, the first item is at position zero:

# my_array = ["first", "second", "third"] 

my_array[0] 

# "first"

Objects 

Usually, you will interact with objects that come from your event data. However you can also create an object using the Object function.

# creating an object 
OBJECT("key1", "value1", "key2", "value2") 

# {key1: "value1", key2: "value2"}
Was this helpful?