> For the complete documentation index, see [llms.txt](https://docs.mydbsync.com/cloud-workflow/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mydbsync.com/cloud-workflow/create-your-workflow/actions/variable.md).

# Variable

The Variable action lets you store data values and use them to make decisions within your workflow. By defining variables and referencing them in conditions, you can build dynamic integrations that respond differently based on the data flowing through each run.

### Add and configure a variable <a href="#step1addandconfigureavariable" id="step1addandconfigureavariable"></a>

{% stepper %}
{% step %}
Drag the **Variable** action into your flow at the point where you want to define the value.
{% endstep %}

{% step %}
Click **Configure**.
{% endstep %}

{% step %}
Enter a name for the variable in the **Variable name** field. For example, `Name`.
{% endstep %}

{% step %}
Assign a value. You can pull the value from a preceding query result or enter a static value for testing.
{% endstep %}

{% step %}
Click **Save**.
{% endstep %}
{% endstepper %}

<div data-with-frame="true"><figure><img src="/files/34IFAjyPBXfPUfFjXnZP" alt=""><figcaption><p>Adding Variables</p></figcaption></figure></div>

We recommend using descriptive, consistent names across your workflow to make your flows easier to read and maintain.

### Add a Debug action (optional) <a href="#step4addadebugactionoptional" id="step4addadebugactionoptional"></a>

To verify what value a variable holds at runtime:

{% stepper %}
{% step %}
Drag a **Debug** action into your flow.
{% endstep %}

{% step %}
Click **Configure**.
{% endstep %}

{% step %}
Drag the variable. For example, `Name` into the debug panel.
{% endstep %}
{% endstepper %}

The variable's value appears in the console output when you run the flow.

### Save and run the flow <a href="#step5saveandruntheflow" id="step5saveandruntheflow"></a>

{% stepper %}
{% step %}
Click **Save** to store your flow configuration.
{% endstep %}

{% step %}
Click the **Run** icon to execute the flow.
{% endstep %}

{% step %}
Monitor the console output to confirm that the variable holds the expected value and that the correct branch runs.
{% endstep %}
{% endstepper %}

<div data-with-frame="true"><figure><img src="/files/kGqaCakFQMTy7OmUU7sq" alt=""><figcaption><p>Console Window</p></figcaption></figure></div>

### Accumulating variable values inside a loop <a href="#accumulatingvariablevaluesinsidealoop" id="accumulatingvariablevaluesinsidealoop"></a>

When you use a Variable action inside a loop, each iteration appends to the variable's running value rather than replacing it.

For example, a formula like `VALUE($myVar) | VALUE(id)` inside a loop collects a new `id` on every iteration. After the loop finishes, downstream actions see the full accumulated result, not just the value from the last iteration.

Use this pattern when you need to gather a list of values across multiple records before passing them to a downstream step, such as a bulk insert or a formatted report.

<div data-with-frame="true"><figure><img src="/files/DaSJdn9DcIfgbc4Z5yIh" alt=""><figcaption></figcaption></figure></div>

For more information about loop behavior, see [For condition](https://docs.mydbsync.com/cloud-workflow/flow-builder/for-loop).

### Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

If a variable condition produces an unexpected result, check the console output from the Debug action to confirm the variable holds the value you expect. Common causes include:

* A preceding query returning no results, leaving the variable empty.
* A mismatch between the variable name in the condition and the name defined in the Variable action.
* Whitespace differences between the variable value and the comparison string.

<details>

<summary>Frequently Asked Questions (FAQ)</summary>

1. What is the purpose of using variables in workflows?

Variables allow you to store and manipulate data dynamically within your workflows, making them more flexible and adaptable to various scenarios.

2. Can I use multiple variables in a single workflow?

Yes, you can define and use multiple variables in a single workflow to handle different pieces of data and conditions.

3. How do I update the value of a variable during a workflow?

You can update the value of a variable using subsequent actions or conditions within your workflow. Simply configure the variable action to assign a new value based on your logic.

4. Is it possible to use variables across different workflows?

Variables are typically scoped to the workflow they are defined in. For cross-workflow data sharing, you may need to use global variables or other methods of data persistence supported by DBSync.

</details>

{% hint style="info" %}
**PRO TIP**

Use meaningful variable names and ensure consistency in naming conventions to make your workflows easier to understand and maintain.
{% endhint %}

### What's next <a href="#whatsnext" id="whatsnext"></a>

* [Implementing conditional logic with If Conditions](https://docs.mydbsync.com/cloud-workflow/if-conditions)
* [For condition](https://docs.mydbsync.com/cloud-workflow/flow-builder/for-loop)
* [Creating and managing queries](https://docs.mydbsync.com/cloud-workflow/ipaas/functional-concepts/query)
* [Debugging flows](https://docs.google.com/document/d/14MCRfISd6NI_tM7yAUu_ci-mz_Y8PzE_Zffq8f4tjDI/edit#heading=h.q8inv0iuih8v)
