Using the Condition Node

Tyler Coleman-Latto
Tyler Coleman-Latto
  • Updated

Overview

A Condition node routes workflow execution down different paths based on logic you define. When the workflow reaches a Condition node, it evaluates each branch in order and follows the first one whose function returns a truthy value. If no branch matches, the execution of the Condition node ends and the workflow continues to the next node.

In this article, we'll be covering how Condition nodes work, how to configure them in the builder, how to name branches for clarity, and the most common patterns for branching workflow logic.

Understanding how Condition nodes work

A Condition node has up to three types of branches, evaluated in order:

  • If — required. Evaluated first. If the function returns truthy, this branch runs.
  • Else if — optional. One or more additional conditions, evaluated in order if the If branch didn't match. The first truthy one wins.
  • Else — Unconditional default branch that runs if no other branch matched. Requires no function.

When a branch matches, execution continues from the node connected to that branch. Nodes on unmatched branches do not run and do not appear in the workflow state for that execution.

The Condition node itself produces no output — state.steps['your-condition-slug'].output is always an empty object {}. All data the condition needs to evaluate should already be in state before the Condition node runs.

Configuring a Condition node

Add a Condition node to your workflow graph, then click it to open the configuration panel. The panel lists the node's name, slug, and each configured branch. Click the pencil icon on any branch to open its Statement details and write its condition function. Use + Add condition to add Else if branches.

Each branch connects to the next node to run via a labeled connector in the graph — If, Else if, or Else. Connect a branch's output to the node that should run when that branch matches. If a branch has no outgoing connection, the Condition node ends and the workflow proceeds to the next node after the condition.

Naming condition branches

You can assign custom names to condition branches to make your workflow graph self-documenting. Instead of structural labels like If or Else if, a branch named "Provisioning complete" or "Awaiting technician" communicates the business logic at a glance without requiring someone to open the node and read the condition code.

Branch names are optional and limited to 50 characters. Each branch name must be unique within the condition node. When no custom name is set, the workflow displays the default positional label. Names appear on the graph edge connecting the branch to its next node, and in the condition node side panel.

Naming the Else branch can be particularly helpful when sharing workflows with non-technical collaborators who may not immediately understand "else" as a programming fallback — a branch labeled "No subscription found" or "Default routing" is more immediately clear than "Else."

Add a name to a branch

  1. Select the Condition node to open its configuration panel.
  2. Locate the branch you want to name (If, Else if, or Else).
  3. Click into the Branch name field for that branch.
  4. Enter a descriptive label. A character counter shows how many characters remain.
  5. Save the workflow. The label appears immediately on the graph edge.

Edit or remove a branch name

  1. Select the Condition node.
  2. In the side panel, locate the branch.
  3. Edit the Branch name field to update the name, or clear it entirely to revert to the default positional label.
  4. Save the workflow.

Branch names follow their branches when you reorder Else if conditions by dragging. The name stays attached to the logic, not the position.

Writing condition functions

Each branch's condition is a TypeScript function that returns a truthy or falsy value. It receives the same arguments as any other workflow function: state, secrets, variables, and utils.

Any truthy value routes execution to that branch. Any falsy value (false, null, undefined, 0, empty string) skips it and moves to the next branch.

Check a value from the trigger input

state.input.status === 'PENDING'

Check the output of a previous node

state.steps['get-account'].output.isActive === true

Check whether a list has items

state.steps['fetch-devices'].output.devices.length > 0

Combine multiple conditions

const account = state.steps['get-account'].output;
return account.status === 'ACTIVE' && account.plan !== 'FREE';

Condition functions have access to utils, including utils.fail() if you want to stop the workflow when data is in an unexpected state rather than silently routing to the else branch. See Using utils in Workflow Functions for details.

Applying common patterns

Simple if/else

The most common pattern: route to one of two nodes depending on a single condition. Configure an If branch with your condition and connect it to the node that should run when the condition is met. Connect the Else branch to the node that should run otherwise.

Multiple outcomes with else if

Use Else if when there are more than two meaningful outcomes. Add as many Else if branches as needed using + Add condition. Branches are evaluated in the order they appear in the panel — the first match wins.

Condition with no else

If no Else branch is configured and no branch matches, the execution of the Condition node ends and the workflow continues normally. Use this when it's valid for no action to be taken — for example, only sending a notification when there's something to report.

Nested conditions

A branch can connect to another Condition node, letting you check a second condition only when the first is met. Each Condition node is evaluated independently, so you can build as many levels of branching as your workflow requires.

Working with state after a Condition node

Only the nodes on the matched branch execute. Nodes on skipped branches are not present in state.steps — referencing them from a downstream node returns undefined.

When both an If and an Else branch converge on the same downstream node, that node needs to handle the case where only one branch's data is available. Check which branch ran before accessing its output:

if (state.steps['send-confirmation']) {
    return { result: state.steps['send-confirmation'].output.messageId };
}
return { result: state.steps['send-insufficient-funds-notice'].output.messageId };

Related to

Was this article helpful?

Have more questions? Submit a request