> 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/all-components/data-transformation/code.md).

# Code

### Overview

The **JavaScript Executable Code Component** (internally identified as `code`) is an advanced action node designed to extend the platform's native capabilities through active programming. Its main function is to execute custom scripts in an isolated environment (*sandbox*), allowing complex mathematical calculations, cleaning or reformatting text strings, manipulating data arrays, and integrating with external systems.

**Mandatory Development Rules:** 1. **External API Consumption:** Whenever there is a need to make HTTP/HTTPS requests (such as methods `GET`, `POST`, `PUT` or `DELETE`) to third-party servers within the script, the use of the library **Axios** (natively injected into the node's global scope).

2. **Data Persistence in the Flow:** The use of the instruction `return` is strictly mandatory at the end of the script. Without the explicit return of an object or variable, the execution engine discards the processing and does not pass the calculated data on to subsequent automation blocks.

### Configuration Parameters

The node's parameterization is simplified and concentrated in the direct coding window:

* **Code:** Highlighted syntax area (*syntax highlighting*) where the developer or administrator types the JavaScript script block (modern ECMAScript) that will be submitted to engine compilation.<br>

### Visual Builder

The graphical interface focuses on isolation and the developer's technical autonomy within the flow builder:

* **Embedded Code Editor:** The builder offers a clean text terminal containing line numbering and quick snippets to facilitate pasting and validation of algorithms. It dispenses with channel selectors or media files, operating purely in the system's logical core.<br>
* **Payload Output Mapping:** In the visual automation map, the block presents one input port and one continuous output port. When saving the structured script with the `return`,<br>

### Special Operators

The logical properties of this component manage the capture of local variables and asynchronous calls:

* **Global Context Injection (`$data`):** The component's JavaScript interpreter grants full access to the object `$data`. This allows the code to read any variable previously stored in the flow (e.g.: `$data.nome`, `$data.telefone`, or payloads from previous question responses) directly within the script expressions.<br>
* **Asynchronous Resolution via Promises (`async/await`):** To ensure the correct processing of external requests without freezing the engine, the node is prepared to interpret asynchronous scopes. The developer can structure functions with `async` and use the `await` operator in Axios calls, ensuring that the `return` final waits for the external API response.<br>

### Practical Examples

The table below demonstrates classic component application scenarios using the correct syntax with Axios and data return:

| **Script Objective**                     | **Configured JavaScript Code in the Builder**                                                                                                                                                           | **Platform Engine Behavior**                                                                                                | **Practical Use Case**                                                                                        |
| ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| **Local String Manipulation**            | <p>const nome = $data.nome;<br><br><br><br>const nomeMaiusculo = nome.toUpperCase();<br><br><br><br>return { nome\_formatado: nomeMaiusculo };</p>                                                      | Captures the CRM variable, turns the letters into uppercase using native JS, and returns the new format to the flow.        | Standardize lead names in the database before sending a formal email notification.                            |
| **External Integration with Axios**      | <p>const cep = <span class="math">data.cep;\<br>\<br> \<br>\<br>const resposta = await axios.get(`https://viacep.com.br/ws/</span>{cep}/json/`);<br><br><br><br>return { endereco: resposta.data };</p> | Performs an external synchronous call using Axios based on the customer's ZIP code and returns the complete address object. | Locate a customer's street and neighborhood completely autonomously after they enter the ZIP code in Webchat. |
| **Conditional Mathematical Calculation** | <p>const valorTotal = $data.total\_carrinho;<br><br><br><br>const desconto = valorTotal \* 0.10;<br><br><br><br>return { valor\_desconto: desconto, total\_final: valorTotal - desconto };</p>          | Performs mathematical equations in server memory and injects the two results as usable variables in the flow.               | Dynamically calculate a 10% discount in the journey and pass the exact amount to the customer's payment link. |


---

# 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.hablla.com/hablla-docs-en/automation-flows/all-components/data-transformation/code.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.
