# 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="/files/4ea3001f8014df5c467d39742e6eb27a0e577bce" alt=""><figcaption></figcaption></figure>

You can access these data using the following syntax:

```plaintext
{{$data?.componentCode?.variablePath}}
```

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

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

If that component doesn't 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**

Besides 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?.component1?.value ?? $data?.component2?.value}}` |
| \|\| (Logical OR - "Or")                           | If the first value is falsy (`false`, `null`, `undefined`, `0`, `""`), use the second | {{$data?.status \|\| "Pending"}}                           |
| `:` (Ternary operator - "If... then... else")      | Works like a ternary operator (if/else)                                               | `{{$data?.age > 18 ? "Adult" : "Minor"}}`                  |
| `&&` (Logical AND - "And")                         | Returns the second value if the first is truthy                                       | `{{$data?.hasDiscount && "Discount Applied"}}`             |

***

| 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`   |
| `===` (Strict equality)      | Compares values and the data type.                                        | `{{5 === "5"}}` → `false` |
| `!=` (Not equal)             | Compares if the values are different.                                     | `{{5 != "5"}}` → `false`  |
| `!==` (Strict not equal)     | Compares if 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. | `{{"Hello, " + "world!"}}` → `"Hello, world!"` |

***

#### 🔀 **Array Operators**

| Operator      | Meaning                                              | Example                                   |
| ------------- | ---------------------------------------------------- | ----------------------------------------- |
| `.length`     | Returns the length of an array.                      | `{{$data?.names.length}}`                 |
| `.includes()` | Checks if a value exists in the array.               | `{{$data?.cities.includes("São Paulo")}}` |
| `.map()`      | Iterates over the elements and transforms the array. | `{{$data?.numbers.map(n => n * 2)}}`      |
| `.filter()`   | Filters elements from the array.                     | `{{$data?.numbers.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 ? "Qualified Lead" : "Unqualified Lead"}}
```

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

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

```plaintext
{{$data?.order?.status ?? "Processing"}}
```

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

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

```plaintext
{{$data?.user?.age >= 18 ? "Adult" : $data?.user?.age > 0 ? "Minor" : "Age not provided"}}
```

🔹 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 When Configuring a Component**

Whenever you are 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 we want to associate with it a person identified in a previous component. We can do it like this:

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

This ensures that if one component doesn't find the person, the other will be used automatically.

***

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

✅ **Use `{{$data?.componentCode?.variablePath}}`** to access data from previous components.\
✅ **Use `??` to set an alternative value in case the first is null or undefined.**\
✅ **Use `||` to set an alternative value in case the first is falsy.**\
✅ **Use `:` to create rules `if/else` inside fields.**\
✅ **Use `&&` to set a value only if the condition is true.**

🚀 **With these techniques, you can create intelligent and customized flows without needing to program!**


---

# 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.hablla.com/hablla-docs-en/automation-flows/using-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.
