Skip to main content
Utils

JavaScript Code

JavaScript Code

Runs a block of custom JavaScript code inside the automation flow and returns the value it produces. Ideal for operations with no dedicated action — complex calculations, data transformations, specific formatting or advanced manipulation of objects and lists.

Tip

Use return in your code to define the value the action returns and makes available to the next steps of the flow.


Options

Code

Write the block of JavaScript code to run. Use return to define the return value.

Reading the output of previous actions

The actions object is available inside the code and holds the returns of every action that came before in the flow. Use the action's ID or alias to read its fields:

javascript
// Syntax: actions["id_or_alias"]["field"]
const texto = actions["lerTexto"]["value"]
const numero = actions["calcularTotal"]["value"]

// Combined in one expression
return `Resultado: ${actions["buscarNome"]["value"]} (${actions["lerCodigo"]["value"]})`
tip

The editor autocompletes the available IDs and fields as you type actions[".

Reading the robot parameters

Use the double-brace syntax inside template literals to embed parameters:

javascript
const url = `https://api.exemplo.com/{{PARAMETROS.endpoint}}`
const token = `{{PARAMETROS.token_api}}`
return token

For secrets (parameters marked as password), use {{SEGREDOS.name}}.

Escape characters and backslashes

The Code field (like any Code type field in a dynamic field) is a real block of JavaScript — everything typed is interpreted with JavaScript's syntax rules before it runs. That means any character that would need escaping inside an ordinary JavaScript string (quotes, line breaks, a backslash and so on) needs escaping here too, exactly as it would in a .js file.

That matters most in Windows file paths, which use the backslash (\) as the separator. Since the backslash is JavaScript's escape character, a path copied straight out of Explorer produces invalid or wrong escape sequences (\t, for instance, becomes a tab, not the letter "t"). To use the path as literal text, write every backslash twice (\\):

javascript
// Wrong — "\t" is read as a tab, not as part of the path
const caminho = "C:\temp\arquivo.txt"

// Right — every backslash doubled to escape it
const caminho = "C:\\temp\\arquivo.txt"
return caminho

The same rule holds inside template literals (` ... ), including when the path is mixed with {{PARAMETROS...}} or actions[...].

Do not escape the dollar sign "$"

Defines whether the $ sign in the code is treated literally, without automatic escaping. Select Yes when the code holds template literals with the ${...} syntax and the default escaping behaviour gets in the way.

Returns

Javascript code

js
actions["action-id"].value // value returned by the custom code (Any)

Field selection

  • value — value produced by the code that ran (Any)

Rules and Conditions

  • The Code field is required.
  • The code must use return to define the return value — without return, the action returns empty.
  • The code runs in an isolated environment with access to the flow variables.
  • Syntax errors or unhandled exceptions in the code stop the robot.

Using external libraries

Besides the built-in libraries, any npm package can be installed and used in the code. See the Install external Node.js libraries tutorial for the full walkthrough.