- Get started
- Build
- Deploy and run
- Examples
- Reference
Script
The Script node runs JavaScript code and returns its result, with the configuration, the JavaScript environment, and examples.
What it does
Runs JavaScript code and passes the return value to the nodes after it.
Configuration reference
| Field | Required | Default | Description |
|---|---|---|---|
| Code | Yes | None | JavaScript code to execute. It must contain a return statement, and the returned value becomes the output of the node. |
The JavaScript environment
Scripts run in an isolated runtime and have access to:
$vars: the workflow's variable scope. The output of earlier nodes is available as$vars.<nodeName>.<property>.$metadata: information about the run, such asInstanceId.- Standard JavaScript built-ins, such as
JSON,Math,Date,Array,Object,String,Number,RegExp,Error,Promise,URL,URLSearchParams, and the timer functions.
For security, the runtime blocks network APIs (fetch, XMLHttpRequest, WebSocket), dynamic code execution (eval, Function), and storage APIs (indexedDB, caches). To call an external API, the HTTP Request node is the alternative.
Scripts are meant for fast, in-memory logic: keep them quick and avoid processing very large payloads, which can exceed runtime limits or time out.
Accessing upstream node output
Earlier nodes are read with $vars.<nodeName>.<property>, where <nodeName> is the ID of the node, shown on the Advanced tab of its properties panel:
// Access HTTP Request node response
const body = $vars.httpRequest1.output.body;
const status = $vars.httpRequest1.output.code;
// Access a workflow variable
const count = $vars.myVariable;
// Access HTTP Request node response
const body = $vars.httpRequest1.output.body;
const status = $vars.httpRequest1.output.code;
// Access a workflow variable
const count = $vars.myVariable;
Return value
The script must return a value. The returned value becomes the node's output, accessible downstream as $vars.<nodeName>.output:
return {
message: "Processed",
count: items.length
};
return {
message: "Processed",
count: items.length
};
Inputs and outputs
Input
The Script node can access any upstream variable via $vars. It does not have a typed input schema — anything in $vars is available.
Output
On success, the output is $vars.<nodeName>.output, which is the return value of the script. Its shape depends on what the script returns.
On failure, when an error handle is connected, the error is $vars.<nodeName>.error:
{
"code": "string",
"message": "string",
"detail": "string",
"category": "string",
"status": 0
}
{
"code": "string",
"message": "string",
"detail": "string",
"category": "string",
"status": 0
}
Generate scripts with AI
The sparkle icon above the code editor accepts a plain-language description of what you want and generates the JavaScript for you. This is useful for accessing an upstream node's output or writing a quick transformation without looking up the exact $vars syntax.
Examples
Example 1: Calculate values for later nodes
// Set a variable that downstream nodes can reference
return {
orderTotal: $vars.httpRequest1.output.body.price * $vars.httpRequest1.output.body.quantity,
currency: "USD"
};
// Set a variable that downstream nodes can reference
return {
orderTotal: $vars.httpRequest1.output.body.price * $vars.httpRequest1.output.body.quantity,
currency: "USD"
};
Downstream nodes access the values as $vars.script1.output.orderTotal and $vars.script1.output.currency.
Example 2: Read an HTTP response
const data = $vars.httpRequest1.output.body;
return {
title: data.title,
userId: data.userId
};
const data = $vars.httpRequest1.output.body;
return {
title: data.title,
userId: data.userId
};
Example 3: Conditional logic
const status = $vars.httpRequest1.output.code;
if (status === 200) {
return { success: true, data: $vars.httpRequest1.output.body };
} else {
return { success: false, statusCode: status };
}
const status = $vars.httpRequest1.output.code;
if (status === 200) {
return { success: true, data: $vars.httpRequest1.output.body };
} else {
return { success: false, statusCode: status };
}
Example 4: Transform an array
const items = $vars.fetchItems1.output.body;
return {
count: items.length,
names: items.map(item => item.name)
};
const items = $vars.fetchItems1.output.body;
return {
count: items.length,
names: items.map(item => item.name)
};
Choosing between Script and Data Transform
| Use Script when... | Use Data Transform when... |
|---|---|
| You need full JavaScript logic — loops, conditionals, string manipulation | You need a simple field mapping or no-code transformation |
| You want to compute something from upstream node output | You want a visual mapper without writing code |
| The transformation is complex or stateful | The transformation is a straightforward reshape |
Next steps
- Variables and data flow:
$vars, expression syntax, and variable scoping. - HTTP Request node: a typical source of data for a Script.
- Decision node: branching on the output of a Script.
- Community: ask questions and share workflows with other builders on the UiPath Forum.
- What it does
- Configuration reference
- The JavaScript environment
- Accessing upstream node output
- Return value
- Inputs and outputs
- Input
- Output
- Generate scripts with AI
- Examples
- Example 1: Calculate values for later nodes
- Example 2: Read an HTTP response
- Example 3: Conditional logic
- Example 4: Transform an array
- Choosing between Script and Data Transform
- Next steps