Skip to main content

Expressions

Learn about expressions in Actioner.


Overview

Expressions are small pieces of JavaScript that allow you to set parameters dynamically in your workflows.

They can use data from:

  • Inputs in manual workflows
  • Events in webhook and integration based triggers
  • Previous nodes
  • The workflow context
  • Your app
  • Connections
  • User running the workflow

You can execute JavaScript within an expression.

Actioner uses its own templating language, and extends it with variables and data transformation methods that help with common tasks, such as retrieving data from other nodes, or accessing the trigger event and manipulating them.

Data in Actioner

When writing expressions, it's helpful to understand data structure and behavior in Actioner. Visit Intro to data and Working with JSON pages for more information on working with data in your workflows.

Writing expressions

To use an expression,

  • Go to the code input field where you want to use an expression.
  • If the field is a select field, checkbox, radio button or date time field, click on gear ⚙ button on the right of the field and then select Dynamic option.
  • Write your expression inside double curlies - {{ }}. All expressions have the format {{ your expression here }}.
Text fields

If the field is a freeform text field, no need to select Dynamic option. You can start typing your expression inside double curlies - {{ }}.

Example: Get data from webhook body

Consider the following scenario: you have a webhook trigger that receives data through the webhook body. You want to extract some of that data for use in your workflow.

Your webhook data looks similar to this:

{
"headers": {
"Content-Type": "application/json",
...
},
"body": {
"event": "user_created",
"user": {
"id": "123456789",
"name": "John Doe",
"email": "johndoe@example.com",
"role": "customer"
}
},
"params": {
"source": "admin_panel"
}
}

In a later node in your workflow, you want to get just the value of email. You can use the following expression:

{{event.body.user.email}}

This expression:

  • Accesses the incoming JSON-formatted data using custom event variable.
  • Finds the value of email (in this example, johndoe@example.com). You can also write this expression as {{event['body']['user']['email']}}.

Example: Writing expressions

An expression contains one line of JavaScript. This means you can't do things like variable assignments or multiple standalone operations. To understand the limitations of JavaScript in expressions, you can start thinking about workarounds.

Imagine you have an action action0 that returns a response with below list of your products. You want to create a new JSON for products that are in stock. The new JSON will contain the product names, prices and categories.

{
...
"body": {
"products": [
{ "name": "Product A", "price": 50.00, "category": "Electronics", "inStock": true, "rating": 4.5 },
{ "name": "Product B", "price": 25.00, "category": "Clothing", "inStock": false, "rating": 3.8 },
{ "name": "Product C", "price": 10.00, "category": "Accessories", "inStock": true, "rating": 4.2 }
]
}
}

Both code examples use the same JS methods to generate the desired JSON, and encloses the code in double curlies, like an expression.

However, the first example isn't a valid expression:

// This example is split over multiple lines for readability
// It is still invalid when formatted as a single line
{{
function filterAndExtract(productsArray) {
const filteredProducts = productsArray.filter(product => product.inStock);
const extractedData = filteredProducts.map(product => ({
name: product.name,
price: product.price,
category: product.category
}));
return JSON.stringify(extractedData, null, 2);
}

filterAndExtract(nodes.action0.response.body.products);
}}

While the second example is valid:

{{JSON.stringify(nodes.action0.response.body.products.filter(product => product.inStock).map(product => ({ name: product.name, price: product.price, category: product.category })))}}