Referencing data

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, i.e. Action A has produced an event.

Now, Action B can make a reference to that data inside the event — 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.

Examples 

Receive email to HTTP Request

A "Receive Email Action" is connected to a downstream "HTTP Request Action". When an email is received, it produces an event which may look like:

{
  "receive_email_action": {
    "from": "potential_phishing@example.com",
    "subject": "Free gift cards",
  }
}

You can then put the sender's email in the downstream "HTTP Request Action" to check the sender domain:

# Access "Receive Email Action"'s sender email
receive_email_action.from

# It will produce
"potential_phishing@example.com"

Page to record

A page called "Submit feedback" is connected to a downstream "Capture record" tool. When the page is submitted, it produces an event containing the user's email and their feedback. The page event may look like:

{
  "submit_feedback": {
    "body": {
      "feedback": "Sample feedback",
      "email": "user@example.com",
    }
}

You can then create a record by referencing the page's feedback in the "Capture record" tool:

# Access "Submit feedback"'s feedback
submit_feedback.body.feedback

# It will produce
"Sample feedback"

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 expressions would fetch it:

RESOURCE.domain_name

If you want to dynamically reference resources based on a variable, there are a couple of ways to do so:

# Upstream action payload
{
  resource_name: "domain_name",
}

# Downstream functions
RESOURCE[upstream_action.resource_name]
GET(RESOURCE, upstream_action.resource_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

If you want to dynamically reference credentials based on a variable, there are a couple of ways to do so:

# Upstream action payload
{
  credential_name: "example_api_key",
}

# Downstream functions
CREDENTIAL[upstream_action.credential_name]
GET(CREDENTIAL, upstream_action.credential_name)

From pages 

Use the special PAGE key to access all Pages in the current Story. If your current Story has a page tool named "Get Email Updates", then PAGE.get_email_updates will retrieve the page's URL.

# To access the "Get Email Updates" page in anywhere in your story:
PAGE.get_email_updates

# It will return the URL of that page:
"https://your-tenant.tines.com/pages/your_page_identifier"

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",
  "url": "https://example.tines.com"
},
"team": {
  "id": 123,
  "name": "Example team",
  "groups": {
    "case_group1": {
      "id": 12345,
      "name": "case group1"
    }
}
},
"story": {
  "id": 123,
  "name": "Example story",
  "key": "example_story",
  "is_draft": false,
  "draft": {
    "id": 12345,
    "name": "draft name"
  }
},
"action": {
  "id": 123,
  "name": "Example action",
  "key": "example_action"
},
"event": {
  "id": 123456789,
  "payload": {
    "array": [
      "the",
      "current",
      "payload",
      "being",
      "processed"
    ]
  }
}
"story_run": {
  "id": "fc7b6392-b602-465b-8f58-ee07d33fa80e"
}

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

META.story.name

Info 

The INFO key exposes relevant information about credentials, resources, and records.

Credentials: Access a credential's name, ID, and metadata values.

INFO.credential.example_credential_name.metadata.example_metadata_key

Resources: Access a resource's name and ID.

INFO.resource.example_resource_name.id

Records: Access a record's ID, name, and fields. For each field, access its ID and name.

INFO.record.example_record_name.fields.story_name.id

Cases: Access case sub-statuses and inputs. For each sub-status, access its ID and name.

INFO.cases.statuses.sub_status_name.id
Was this helpful?