Referencing data
Formulas are all about referencing and transforming data. References can be derived from three locations:
Event data from an upstream action
Content of Credentials, Pages, Resources
Information about your environment
Reference data from upstream actions
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. Learn more here.
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"Access data from credentials, pages, resources
Data stored in these three areas can be dynamically referenced at any time using the following keywords:
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_keyIf 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)To pass a credential reference to another action without resolving it, escape it. You need this when an HTTP Request action sets another action's options through the API:
In text, put a backslash before the reference:
\<<CREDENTIAL.example_api_key>>.In a formula, write the reference as a string:
"<<CREDENTIAL.example_api_key>>".
The receiving action stores the reference and resolves it when it runs. Without the escape, the sending action resolves the reference first and sends the credential's value. When plaintext credential blocking is on for your tenant, that request fails. See Credential values in action options.
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"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_nameIf 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)Access information about your environment
Use the info, metadata, and paginate
Info
The INFO key exposes relevant information about cases, credentials, resources, and records.
Credentials: Access a credential's name, ID, and metadata values.
INFO.credential.example_credential_name.metadata.example_metadata_keyResources: Access a resource's name and ID.
INFO.resource.example_resource_name.idRecords: Access a record's ID, name, and fields. For each field, access its ID and name.
INFO.record.example_record_name.fields.story_name.idCases: Access case sub-statuses, priorities and case fields within the team.
For each sub-status, view its ID and name.
For each case field, view the ID, name, slug, markdown reference, type, and validation options
For each case priority, view its name
INFO.cases.statuses.sub_status_name.id
INFO.cases.case_field_input_name.id
INFO.cases.priorities.priority_name.nameMetadata
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.namePaginate
The PAGINATE key can be used in HTTP Request Actions with pagination enabled to access information about the pagination run.
Index: Returns the current index of the pagination loop, starting at 0 for the first page request.
PAGINATE.indexPrevious response: Returns the HTTP response of the previous page. This is useful when you need to get a link to the next page or determine the total number of pages left. This value will be null for the first request.
PAGINATE.previous_responseLearn more about using PAGINATE.index and PAGINATE.previous_response in our HTTP Request Action pagination guide.
All formula keywords
Below is a list of all keywords you can reference when building a formula.