Skip to main content
Version: 1.5.x

Define Variable Function

In workflows, defining variables is a crucial step for managing dynamic data and creating personalized user experiences. Variables allow you to store and manipulate data at different stages of the workflow, making it easier to customize messages, control workflow logic, and track user interactions.


Define Variable Function

Adding Define Variable Step

To define a variable in a workflow, follow these steps:

  1. Navigate to the Workflow Editor: Open the workflow where you want to add the variable.
  2. Add a Define Variable Step: Drag and drop the "Define Variable" step from the side panel into your workflow sequence.
  3. Configure the Variable:
    • Name: Enter a unique name for the variable. This name will be used to reference the variable throughout the workflow.
    • Value: Assign a value to the variable. You can use string literals enclosed in single quotes, variables starting with data., or JavaScript expressions. For example:
      • 'Hello, World!' (string literal)
      • data.recipient.name (variable from the recipient profile data)
      • 'Hi ' + data.recipient.name (concatenation using JavaScript)

Using the Variable Globally

Once defined, variables can be accessed globally throughout the workflow. This includes different steps or channel templates.

Using the Variable in Workflow Steps

To reference a variable within workflow steps, use the syntax data.variables.<variableName>. For example, if you defined a variable named name with the value 'John', you can use the variable in any step by calling data.variables.name.

Using the Variable in Channel Templates

To reference a variable in channel templates, use the syntax {{variables.<variableName>}}. For example, if you defined a variable named greeting with the value 'Hi ' + data.recipient.name, you can use {{variables.greeting}} in email or SMS templates to personalize messages.

Examples

Example 1: Simple Greeting

  • Variable Name: greeting
  • Value: 'Hello, ' + data.recipient.name

You can then use {{variables.greeting}} in an email or SMS template to greet the recipient by name.

Conditions for Define Variable Step

You can set conditions for when the variable should be defined using the Condition Builder. This feature is useful for creating dynamic and context-sensitive workflows, where variables are defined based on specific criteria, such as user attributes or event types.

tip

Utilize the Condition Builder to add conditions for the define variable step, enabling more dynamic workflows.

Best Practices

  • Naming: Use descriptive and meaningful names for your variables to enhance workflow clarity and maintainability.
  • Consistency: Ensure consistent naming and usage of variables across workflows to minimize confusion.