> For the complete documentation index, see [llms.txt](https://docs.ixhello.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ixhello.com/ixhc2/flows/flow-editor/set-variable-node.md).

# Set Variable Node

### Overview

The Set Variable Node lets builders create or update variables directly within a flow. It is designed for mid-flow calculations, data transformation, and state management without relying on an API response or Agent slot filling.

Builders can use it to perform tasks such as:

* combining first and last names
* calculating tax or totals
* formatting API values for display
* setting flags for downstream logic
* preparing values for Branch Nodes or other nodes

### Problem it solves

1. Supports mid-flow data updates
   1. Before this feature, variables were only updated when:
      1. an API returned data, or
      2. an Agent filled a slot
   2. There was no dedicated way to manipulate values during the flow itself.
2. Removes simple logic from Agents
   1. Instead of asking an Agent to calculate, format, or derive values, the flow can now handle those tasks directly.
   2. This improves reliability and reduces unnecessary LLM usage.
3. Makes flow logic more visible
   1. Variable transformations are shown explicitly on the canvas.
   2. This is easier to maintain than hiding logic inside prompts or backend services.

***

### Why use the Set Variable Node

The **Set Variable** node helps you create, update, and transform data during a flow without relying on an LLM for simple tasks.

#### 1. Data Flexibility

* Convert raw data into more useful formats.
* Combine, format, or calculate values as needed.

**Examples:**

* Combine `firstName` and `lastName` into `fullName`.
* Calculate `taxAmount` from a `subtotal`.

#### 2. Faster and More Cost-Effective

* Performs simple calculations and formatting instantly.
* Reduces unnecessary LLM calls, improving performance and lowering costs.

#### 3. Clear Flow Logic

* Makes data changes visible directly in the flow.
* Helps builders easily understand where variables are created or updated.

#### 4. Better Developer Experience

* Provides a structured way to manage flow data and session state.
* Makes it easier to build and maintain complex workflows.

#### 5. Improved Reliability

* Handles straightforward transformations without LLM interpretation.
* Reduces the risk of incorrect outputs for simple operations.

***

### How the Set Variable Node Works

#### 1. Create or Update Variables

* Create new variables or update existing ones.
* New values can replace previous values when needed.

#### 2. Multiple Assignments in One Node

* A single node can contain multiple variable assignments.
* Assignments are displayed as a list in the node configuration.

#### 3. Sequential Execution

* Assignments run from top to bottom.
* Variables updated in one row can be used by the next row immediately.

#### 4. Expression Support

The node supports expressions for:

* Mathematical calculations
* String formatting
* Boolean logic
* JSON processing
* Array operations
* Other supported data transformations

***

### User workflow

1\. Add the node to the flow

* In the Flow Editor, drag a Set Variable Node onto the canvas.
* Place it where you need to create or transform data before the next step.

2\. Add assignment rows

* In the node sidebar or drawer, add one or more assignment rows.
* Each row represents one variable assignment.

3\. Configure each assignment

* For each row, define:
  * Variable Name
  * Value
  * Type

4\. Arrange assignments in order

* Add more rows as needed.
  * The assignments are processed in the order shown.
  * Order matters when one row references a value created in a previous row.

5\. Review the node summary

* On the canvas, the node body displays the total number of assignments.

6\. Connect the node

* Wire the node’s single output handle to the next step in the flow.

7\. Runtime execution

* At runtime, the engine executes the assignments top-to-bottom.
  * After each row runs, the flat session context is updated immediately.
  * This allows the next row to reference values created earlier in the same node.

***

### Example use cases

Refer to this tutorial demonstrates how to build, validate and test a customer v2 flow using the [Flow editor](/ixhc2/flows/flow-editor.md) - [Build Flow](/ixhc2/general/tutorials/build-validate-and-test-a-simple-flow.md)

**Use Case: Loyalty points calculation**

This is a **customer rewards tier calculation workflow** that determines a member's loyalty tier based on their points and displays the appropriate message.

#### Step 1: Start

The flow begins when the workflow is triggered.&#x20;

* **Node:** `start`

#### Step 2: Say Node - Display Welcome Message

A greeting message is shown to the user.

<table><thead><tr><th width="141">Setting</th><th>Description</th></tr></thead><tbody><tr><td>Node Name</td><td>Greetings</td></tr><tr><td>Message</td><td>Welcome to Demo Rewards! Let's spin up a sample member and check their tier.</td></tr><tr><td>Purpose</td><td><p></p><ul><li>Introduces the rewards program.</li><li>Informs the user that the system will check a sample member's rewards status.</li></ul></td></tr></tbody></table>

<figure><img src="/files/7V5HiyoFcJ369f2qJkn4" alt="" width="352"><figcaption></figcaption></figure>

#### Step 3: Initialize Member Points - Set Node 1

The flow sets an initial points value for the member.

<table><thead><tr><th width="272">Setting</th><th>Value</th></tr></thead><tbody><tr><td>Name</td><td>seed_points</td></tr><tr><td>Variable to Set</td><td><p></p><ul><li>Creates or assigns a value to the <code>points</code> variable.</li><li>This acts as sample member reward points.</li></ul><p>Variable: Points</p><p>Set to: Math.floor(Math.random() * 3000)</p><p>Type: Number                                                                                                 </p></td></tr><tr><td>Purpose</td><td>Provides input data for tier calculation.</td></tr></tbody></table>

<figure><img src="/files/wCKWvZhn4TV8Ml1YUqrH" alt="" width="353"><figcaption></figcaption></figure>

#### Step 4: Calculate Tier Information - Set Node 2

The system computes the member's tier and any bonus points.

<table><thead><tr><th width="272">Setting</th><th>Value</th></tr></thead><tbody><tr><td>Name</td><td>compute_tier</td></tr><tr><td>Variable to Set 1</td><td><p>Variable: bonus_points</p><p>Set to: Math.round(points * 0.15)</p><p>Type: Number                                                                                                 </p></td></tr><tr><td>Variable to Set 1</td><td><p>Variable: total_points</p><p>Set to: points + bonus_points</p><p>Type: Number           </p></td></tr></tbody></table>

<figure><img src="/files/m0r9YzEAzhd60Jdwte4I" alt="" width="323"><figcaption></figcaption></figure>

#### Step 5: Error Handling (if calculation fails)

If there is an issue during the tier calculation, the flow follows the **Error** path.

**Node:** `calc_error`

Message: "Sorry, something went wrong computing the tier."

End.

#### Step 6: Route User to Appropriate Tier

If calculation succeeds, the flow proceeds to a branching decision.

<table><thead><tr><th width="272">Setting</th><th>Value</th></tr></thead><tbody><tr><td>Name</td><td>route_tier</td></tr><tr><td>Branching Rule 1</td><td><p>Expression: total_points >= 2000</p><p>Branch Name: platinum                                                                                         </p></td></tr><tr><td>Branching Rule 2</td><td><p>Expression: total_points >= 1000</p><p>Branch Name: gold     </p></td></tr><tr><td>Branching Rule 3</td><td><p>Expression: total_points >= 500</p><p>Branch Name: silver </p></td></tr><tr><td>Branching Rule 4</td><td><p>Expression: total_points > 0</p><p>Branch Name: bronze</p></td></tr></tbody></table>

<figure><img src="/files/uhVXAuqAIfCNma1Dgklg" alt="" width="315"><figcaption></figcaption></figure>

#### Step 7: Say Node

<table><thead><tr><th width="141">Setting</th><th>Description</th><th></th><th></th><th></th><th></th></tr></thead><tbody><tr><td>Node Name</td><td>platinum_message</td><td>gold_message</td><td>silver_message</td><td>bronze_message</td><td>no_points_message</td></tr><tr><td>Message</td><td>This member has {{points}} points, plus a 15% bonus of {{bonus_points}}, for {{total_points}} total — that's PLATINUM tier! Concierge service and every perk unlocked.</td><td>This member has {{points}} points, plus a 15% bonus of {{bonus_points}}, for {{total_points}} total — that's GOLD tier! Keep earning to reach Platinum at 2000.</td><td>This member has {{points}} points, plus a 15% bonus of {{bonus_points}}, for {{total_points}} total — that's SILVER tier! Free shipping unlocked.</td><td>This member has {{points}} points, plus a 15% bonus of {{bonus_points}}, for {{total_points}} total — that's BRONZE tier. Keep earning to reach Silver at 500!</td><td>This member has no points yet. Make a purchase to start earning!</td></tr><tr><td>Allow barge-in</td><td>Yes</td><td>Yes</td><td>Yes</td><td>Yes</td><td>Yes</td></tr></tbody></table>

#### Step 8: End

All message nodes converge into the same endpoint.

**Node:** `end`

Purpose: Terminates the workflow after displaying the appropriate tier message.

#### Complete Flow:

<figure><img src="/files/KBMJymFNJ2H6AT5PapHQ" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.ixhello.com/ixhc2/flows/flow-editor/set-variable-node.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
