# Variables

Variable is a temporary data holder used to store, reuse, and manipulate values during workflow execution.

Variables help you:

* Store API responses or transformed values
* Pass data between steps
* Control workflow logic dynamically

{% hint style="info" %}
Tip: Think of variables as memory boxes that live during workflow execution.
{% endhint %}

Earlier, many use cases relied on Code Runner snippets, but variables simplify this by reducing the need for custom code, improving workflow readability, making flows easier to debug and maintain, and enabling non-developers to configure and adjust logic with confidence.

### Supported Data Types

Variables support the following data types:

* String
* Number
* JSON (includes Array, List or Object)&#x20;
  * Refer this [IETF Document](https://datatracker.ietf.org/doc/html/rfc8259) to learn more about JSON format.
* Datetime

### Variable Declaration Guidelines

#### Declaration Areas

1. [Initialize Variable Step](#initialize-variable)
2. [Pre-step variable declaration](#pre-step-variable)
3. [Post-step variable declaration](#post-step-variable)

#### Naming Guidelines

* Use camelCase
* Use meaningful names
* Avoid spaces or special characters

Examples:

* ✅ orderId ❌ Order Id
* ✅ customerEmailAddress ❌ Customeremailaddress (for better readability)

### Initialize Variable

Initialize Variable is a step used to declare a variable and assign its initial value before it is used anywhere in the workflow.

#### When to Initialize?

* At the start of a workflow
* Before using a variable in conditions, API mapping, or transformations

**Examples**

{% columns %}
{% column %}
Variable Name: *customerEmail*

Initial Value: *""*

Type: *String*
{% endcolumn %}

{% column %}
Variable Name: *retryCount*

Initial Value: *0*

Type: *Number*
{% endcolumn %}
{% endcolumns %}

### Pre-Step & Post-Step Variables

#### Execution order

Pre-Step Variables → Actual Step Execution → Post-Step Variables

#### Pre-Step Variable

Pre-step variables are executede before the actual execution of a step.

Used for:

* Preparing input data
* Modifying request payloads
* Setting headers or query parameters
* Conditional execution

**Examples**

Before making Create Customer API call, to set a page limit of 1000 and to increment the page number by 1. It will increment the existing page number before making the api call.

{% columns %}
{% column width="50%" %}
Variable Name: page\_limit

Value: 1000

Type: *Number*
{% endcolumn %}

{% column width="50%" %}
Variable Name: page\_number

Value: `{{ page_number.increment()   }}`

Type: *Number*
{% endcolumn %}
{% endcolumns %}

#### Post-Step Variable

Post-step variables are executed after the respective step execution. Step responses can be referenced, but these variable definitions or updates are executed only after the step, so it cannot be accessed inside the step. Available to all downstream steps

**Used for**

* Storing API responses
* Extracting IDs
* Passing data to next steps
* Error or success validation

**Examples**

To store the customer ID which is returned in the response of that step, we can create post-step variable as following

{% columns %}
{% column width="58.333333333333336%" %}
Variable Name: createdCustomerId

Value: `{{ <particular_step_id>.response.id }}`&#x20;

Type: *Datahub*
{% endcolumn %}

{% column width="41.666666666666664%" %}

{% endcolumn %}
{% endcolumns %}

### How to Use Variables

Variables can be used anywhere DataHub values are allowed. Just like referencing responses from another step, variables can be easily called and reused throughout the flow.

#### Using Variables in API Mapping

```
{
  "email": "{{variables.customerEmail}}",
  "id": "{{variables.createdCustomerId}}"
}
```

#### Using Variables in Conditions

Condition:

```
{{variables.retryCount}} < 3
```

#### Updating Variable Value

Variables can be updated by assigning a static value or using [inline transformation](/project-manager/workflows/inline-transformations.md).

```
{{variables.retryCount.increment()}}
```

{% hint style="success" %}
If variables are used without being declared or initialized, they will return `null` or `None`. This is handled gracefully and will not throw any errors.
{% endhint %}

#### Steps Supporting Pre-Step & Post-Step Variables

{% columns %}
{% column %}

* API Step
* Decision Step
* Loop Step
  {% endcolumn %}

{% column %}

* Formatter Step
* Notification Step
* Code Runner Step
  {% endcolumn %}

{% column %}

* Detail Logger Step
* Set Response Step
* Snippet Step
  {% endcolumn %}
  {% endcolumns %}

{% hint style="info" %}
Initialize Variable is a standalone step at the start of the workflow.
{% endhint %}

### Variable Overview Panel

Since variables are defined inside steps, a Variable Overview Panel is provided for visibility and management. From this panel, you can:

* View all variables used in the workflow
* See each variable’s data type
* Identify which steps create or update each variable
* Jump directly to those steps
* Search or filter variables

The panel also clearly distinguishes variables that share the same name across:

* Workflow scope
* Snippet scope

### Deleting a Step

If a step that creates or updates variables is deleted:

* All variable operations from that step are removed
* A warning lists the affected variables
* You can choose to move or reassign those variables
* Any unresolved issues appear in the Global Error Panel

{% hint style="danger" %}
All variable operations from that step are removed
{% endhint %}

### Snippets and Variable Scope

* Variables created inside a snippet are accessible only within that snippet
* Variables created at the workflow level remain accessible across all workflow steps


---

# Agent Instructions: 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:

```
GET https://docs.dckapintegrator.com/project-manager/workflows/variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
