> For the complete documentation index, see [llms.txt](https://docs.hablla.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hablla.com/hablla-docs-en/automation-flows/using-variables.md).

# Using variables

In Hablla, when configuring an automation flow, you can use **variables** to retrieve data from previous components and expressions **logical and conditional** to make your automations more dynamic and intelligent.

This allows information to be reused automatically, without needing to fill it in manually, making the process more efficient and error-free.

### 🎯 **What Are Variables in Hablla?**

Each component within a flow has a **unique code** and can generate **output data** that can be used by other components in the same flow.

<figure><img src="https://1592162275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrmxWrIrMauHcIrsuqfGq%2Fuploads%2FWpztEh7gCvaKUGA9aENC%2Fimage.png?alt=media&amp;token=f7845359-1265-4bad-91a6-7b747e789e21" alt=""><figcaption></figcaption></figure>

You can access this data using the following syntax:

```plaintext
{{$data?.codigoDoComponente?.caminhoVariavel}}
```

➡ **Real example:**\
If a component called `whatsappReceptive_tmy0de` identified a person, and their ID is stored in the field `person.id`, we can access this value like this:

```plaintext
{{$data?.whatsappReceptive_tmy0de?.person?.id}}
```

If this component does not return a valid value, we can try a second component called `whatsappReceptive_r2b7wr`:

```plaintext
{{$data?.whatsappReceptive_tmy0de?.person?.id ?? $data?.whatsappReceptive_r2b7wr?.person?.id}}
```

📌 Here, `??` means: **if the first value is null or undefined, use the second.**

***

### 🔥 **Operators and Expressions in Hablla**

In addition to accessing variables, you can use **logical operators** to create rules and conditions within your flows.

#### 🛠 Logical and Conditional Operators

| Operator                                           | Meaning                                                                               | Example                                                       |
| -------------------------------------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| `??` (Nullish Coalescing - "If null or undefined") | If the first value is null or undefined, use the second                               | `{{$data?.componente1?.valor ?? $data?.componente2?.valor}}`  |
| \|\| (Logical OR - "Or")                           | If the first value is false (`false`, `null`, `undefined`, `0`, `""`), use the second | {{$data?.status \|\| "Pendente"}}                             |
| `:` (Ternary operator - "If... then... else")      | Works like a ternary operator (if/else)                                               | `{{$data?.idade > 18 ? "Maior de idade" : "Menor de idade"}}` |
| `&&` (Logical AND - "And")                         | Returns the second value if the first is true                                         | `{{$data?.temDesconto && "Desconto Aplicado"}}`               |

***

| Operator             | Meaning                                | Example            |
| -------------------- | -------------------------------------- | ------------------ |
| `+` (Addition)       | Adds two values.                       | `{{5 + 3}}` → `8`  |
| `-` (Subtraction)    | Subtracts two values.                  | `{{10 - 4}}` → `6` |
| `*` (Multiplication) | Multiplies two values.                 | `{{3 * 4}}` → `12` |
| `/` (Division)       | Divides two values.                    | `{{10 / 2}}` → `5` |
| `%` (Modulo)         | Returns the remainder of the division. | `{{10 % 3}}` → `1` |

***

#### 🔍 **Comparison Operators**

| Operator                     | Meaning                                                                   | Example                   |
| ---------------------------- | ------------------------------------------------------------------------- | ------------------------- |
| `==` (Equality)              | Compares values without checking the type.                                | `{{5 == "5"}}` → `true`   |
| `===` (Strictly equal)       | Compares values and data type.                                            | `{{5 === "5"}}` → `false` |
| `!=` (Different)             | Compares whether the values are different.                                | `{{5 != "5"}}` → `false`  |
| `!==` (Strictly different)   | Compares whether the values and types are different.                      | `{{5 !== "5"}}` → `true`  |
| `>` (Greater than)           | Returns `true` if the first value is greater than the second.             | `{{10 > 5}}` → `true`     |
| `<` (Less than)              | Returns `true` if the first value is less than the second.                | `{{3 < 7}}` → `true`      |
| `>=` (Greater than or equal) | Returns `true` if the first value is greater than or equal to the second. | `{{8 >= 8}}` → `true`     |
| `<=` (Less than or equal)    | Returns `true` if the first value is less than or equal to the second.    | `{{6 <= 5}}` → `false`    |

***

#### 🔄 **String Operators**

| Operator            | Meaning            | Example                                      |
| ------------------- | ------------------ | -------------------------------------------- |
| `+` (Concatenation) | Joins two strings. | `{{"Olá, " + "mundo!"}}` → `"Hello, world!"` |

***

#### 🔀 **Array Operators**

| Operator      | Meaning                                            | Example                                    |
| ------------- | -------------------------------------------------- | ------------------------------------------ |
| `.length`     | Returns the size of an array.                      | `{{$data?.nomes.length}}`                  |
| `.includes()` | Checks whether a value exists in the array.        | `{{$data?.cidades.includes("São Paulo")}}` |
| `.map()`      | Iterates over the elements and modifies the array. | `{{$data?.numeros.map(n => n * 2)}}`       |
| `.filter()`   | Filters array elements.                            | `{{$data?.numeros.filter(n => n > 5)}}`    |

### 🔍 **How to Use IF/ELSE Conditions**

In Hablla, you can create **conditional rules** within flows. See how it works:

#### ✅ **Example 1: Check if a customer is qualified**

```plaintext
{{$data?.lead?.score > 50 ? "Lead Qualificado" : "Lead Não Qualificado"}}
```

If the lead score is **greater than 50**, the result will be `"Qualified Lead"`, otherwise, `"Unqualified Lead"`.

#### ✅ **Example 2: Set a default status**

```plaintext
{{$data?.pedido?.status ?? "Em processamento"}}
```

If the order status exists, it will be used. Otherwise, the default status `"Processing"` will be applied.

#### ✅ **Example 3: Combine multiple conditions**

```plaintext
{{$data?.usuario?.idade >= 18 ? "Maior de idade" : $data?.usuario?.idade > 0 ? "Menor de idade" : "Idade não informada"}}
```

🔹 If the age is greater than or equal to **18**, the result will be `"Adult"`.\
🔹 If the age is greater than **0**, but less than **18**, the result will be `"Minor"`.\
🔹 If the age is not provided, the result will be `"Age not provided"`.

***

### 🎯 **How to Use These Expressions in Component Configuration**

Whenever you're configuring a component in Hablla, you can use these expressions in fields where you want to insert dynamic values.

📌 **Practical example:**\
Suppose we are creating a new card in the flow and want to associate a person identified in a previous component with it. We can do it like this:

```plaintext
{{$data?.whatsappReceptive_tmy0de?.person?.id ?? $data?.whatsappReceptive_r2b7wr?.person?.id}}
```

This ensures that, if one component does not find the person, the other will be used automatically.

## Best practices for using variables

When using variables in automation flows, it is important to understand the difference between **unique identifiers** and **descriptive attributes**.

Some fields represent characteristics of an entity and can change over time, such as:

```
name
std_name
status
description
```

Other fields exist specifically to identify an entity uniquely, such as:

```
id
```

### Prefer `id` for permanent references

Whenever an automation needs to identify a specific entity — for example, a tag, person, list, department, card, or other object — prefer using the field `id`.

Example:

```
{{$data?.componente?.id === "IDENTIFICADOR_DA_ENTIDADE"}}
```

The `id` is the most suitable reference for automations that need to remain stable over time.

This prevents registration changes from affecting the flow logic.

### Use descriptive attributes to compare values

Fields like `name` and `std_name` can be used normally when the automation's goal is to evaluate the current content of a property.

Example:

```
{{$data?.componente?.status === "active"}}
```

or:

```
{{$data?.componente?.name === "Cliente Premium"}}
```

In this case, the automation is deliberately comparing the value of that attribute.

The difference lies in the objective of the condition:

* to identify a specific entity, use `id`;
* to evaluate a characteristic of the entity, use the corresponding attribute.

### Why is this important?

Descriptive attributes can change during the entity's lifecycle.

For example, a name can be edited later without the object ceasing to be the same.

The identifier still represents the same entity:

```
id = specific entity
name = current characteristic of the entity
std_name = normalized representation of the name
```

Therefore, an automation built based on the `id` tends to be more resilient to future changes.

### Generic example

Consider an entity with the following data:

```
{
  "id": "abc123",
  "name": "VIP Customer",
  "std_name": "vip_customer"
}
```

To permanently identify this entity:

```
{{$data?.componente?.id === "abc123"}}
```

To check whether the current name is `"VIP Customer"`:

```
{{$data?.componente?.name === "VIP Customer"}}
```

These are two different uses.

The first identifies the object.

The second compares a property of the object.

### Recommended rule

To build more robust automations:

```
Entity identification → use id
Attribute comparison → use the corresponding attribute
```

Whenever there is a `id` available and the intention is to reference a specific entity, it should be the preferred option.

> **Good practice:** whenever you need to create a permanent reference to an entity within an automation, prefer using the field `id`. Fields like `name` and `std_name` should be used when the intention is to compare their current values.

***

### 🔥 **Summary: How to Use Variables and Expressions in Hablla**

✅ **Use `{{$data?.codigoDoComponente?.caminhoVariavel}}`** to access data from previous components.\
✅ **Use `??` to define an alternative value if the first is null or undefined.**\
✅ **Use `||` to define an alternative value if the first is false.**\
✅ **Use `:` to create rules `if/else` within fields.**\
✅ **Use `&&` to define a value only if the condition is true.**

🚀 **With these techniques, you can create smart and personalized flows without needing to code!**


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.hablla.com/hablla-docs-en/automation-flows/using-variables.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
