Set Variable

Definition

This action allows you to manage and manipulate variables within your workflow. It enables you to clear, set, or append data to a selected variable, giving you flexibility in handling dynamic data during execution. This is a versatile tool for storing, updating, or combining information as your workflow progresses, making it essential for creating adaptive and efficient automation processes.

If you're unfamiliar with variables and how they work in Zenphi, refer to this guide: What Are Variables?.

Example Use Cases

  1. Store User Input
    Capture and store user-provided data from a form or an API response into a variable for later use in the workflow.

  2. Update Dynamic Values
    Replace old data in a variable with new information, such as updating the status of a process or storing the latest timestamp.

  3. Build Data Collections
    Append multiple pieces of data to a variable to create a list or a combined string, such as compiling email addresses or concatenating messages.

  4. Reset Variables
    Clear the contents of a variable to ensure no residual data affects subsequent steps in the workflow.

  5. Track Iterative Processes
    Use a variable to accumulate results or count iterations within a loop for monitoring progress or generating reports.


Inputs

  1. Variable
    Select an existing variable from your workflow or create a new one by clicking the plus (+) button. This is the variable that will be modified by the action.

  2. Operation
    Choose the operation to perform on the selected variable:

    • Clear: Empties the variable, removing all stored data.
    • Set: Replaces the current data in the variable with new input data.
    • Append: Adds the new input data to the existing data in the variable. This is useful for building lists or concatenating strings.

Step-by-Step Guide

  1. Add the Action to Your Flow
    Drag and drop the Set Variable action into your workflow at the desired location where you want to modify a variable.

  2. Select or Create a Variable
    In the Variable field, choose an existing variable from the dropdown menu or create a new one by clicking the plus (+) button. Ensure the variable name reflects its purpose in the workflow.

  3. Choose the Operation
    Select the appropriate operation for your use case:

    • Clear to reset the variable.
    • Set to replace the existing value.
    • Append to add new data to the current value.
  4. Provide Input Data (if applicable)
    If using the Set or Append operation, input the data you want to store or add to the variable. This could be static text, dynamic values from previous steps, or calculated data.


Example: Advanced Control with Variables

Variables in Zenphi can be used not only for storing data but also for dynamically controlling the direction of your flow based on conditions or events. For instance, you can use a Boolean variable like SkipTheseSteps to determine whether certain sections of your flow should execute, allowing for more flexible and adaptive workflows.

How to Use Set Variable in This Scenario

Imagine you have a flow where a decision made early on impacts several steps later. Here's how you can use the Set Variable action to control the flow:

  1. Define the Variable
    Create a Boolean variable, such as SkipTheseSteps, and set its default value to false.

  2. Set the Variable Based on Conditions
    In the early steps of your flow, use the Set Variable action to change the value of SkipTheseSteps based on specific conditions. For example:

    • If a user chooses a specific option in a form or an API response indicates a certain status, you can set SkipTheseSteps to true.
  3. Control the Flow Later
    In a subsequent part of your flow, insert an If Condition action to check the value of SkipTheseSteps.

    • If SkipTheseSteps = true, bypass the steps inside the "true" branch of the condition.
    • If SkipTheseSteps = false, proceed with the actions in the "false" branch.

Example Scenario

Suppose you’re building an approval workflow:

  • Early in the flow, you determine that a specific approval step is not required based on the request type.
  • You use the Set Variable action to set SkipTheseSteps = true.
  • Later in the flow, an If Condition checks this variable, and the approval step is skipped if SkipTheseSteps is true.

This approach allows you to dynamically adjust the flow without hardcoding every possibility, making your automation more robust and adaptable.

For a detailed walkthrough, refer to this guide: Zenphi Community - Skip Steps in Your Automation.