mirror of
https://github.com/n8n-io/n8n-docs.git
synced 2025-11-20 17:48:34 +00:00
wip
This commit is contained in:
parent
a53d7f76dc
commit
aa111d970c
@ -2,33 +2,58 @@
|
||||
contentType: reference
|
||||
---
|
||||
|
||||
# `$("<node-name>").all(branchIndex?: number, runIndex?: number)`
|
||||
# `("<node-name>").all(branchIndex?: number, runIndex?: number)`
|
||||
|
||||
This gives access to all the items of the current or parent nodes. If you don't supply any parameters, it returns all the items of the current node.
|
||||
|
||||
## Getting items
|
||||
|
||||
```typescript
|
||||
// Returns all the items of the given node and current run
|
||||
const allItems = $("<node-name>").all();
|
||||
=== "JavaScript"
|
||||
```js
|
||||
// Returns all the items of the given node and current run
|
||||
let allItems = $("<node-name>").all();
|
||||
|
||||
// Returns all items the node "IF" outputs (index: 0 which is Output "true" of its most recent run)
|
||||
const allItems = $("IF").all();
|
||||
// Returns all items the node "IF" outputs (index: 0 which is Output "true" of its most recent run)
|
||||
let allItems = $("IF").all();
|
||||
|
||||
// Returns all items the node "IF" outputs (index: 0 which is Output "true" of the same run as current node)
|
||||
const allItems = $("IF").all(0, $runIndex);
|
||||
// Returns all items the node "IF" outputs (index: 0 which is Output "true" of the same run as current node)
|
||||
let allItems = $("IF").all(0, $runIndex);
|
||||
|
||||
// Returns all items the node "IF" outputs (index: 1 which is Output "false" of run 0 which is the first run)
|
||||
const allItems = $("IF").all(1, 0);
|
||||
```
|
||||
// Returns all items the node "IF" outputs (index: 1 which is Output "false" of run 0 which is the first run)
|
||||
let allItems = $("IF").all(1, 0);
|
||||
```
|
||||
=== "Python"
|
||||
```python
|
||||
# Returns all the items of the given node and current run
|
||||
allItems = _("<node-name>").all();
|
||||
|
||||
# Returns all items the node "IF" outputs (index: 0 which is Output "true" of its most recent run)
|
||||
allItems = _("IF").all();
|
||||
|
||||
# Returns all items the node "IF" outputs (index: 0 which is Output "true" of the same run as current node)
|
||||
allItems = _("IF").all(0, _runIndex);
|
||||
|
||||
# Returns all items the node "IF" outputs (index: 1 which is Output "false" of run 0 which is the first run)
|
||||
allItems = _("IF").all(1, 0);
|
||||
```
|
||||
|
||||
## Accessing item data
|
||||
|
||||
Get all items output by a previous node, and log out the data they contain:
|
||||
|
||||
```typescript
|
||||
previousNodeData = $("<node-name>").all();
|
||||
for(let i=0; i<previousNodeData.length; i++) {
|
||||
console.log(previousNodeData[i].json);
|
||||
}
|
||||
```
|
||||
=== "JavaScript"
|
||||
```typescript
|
||||
previousNodeData = $("<node-name>").all();
|
||||
for(let i=0; i<previousNodeData.length; i++) {
|
||||
console.log(previousNodeData[i].json);
|
||||
}
|
||||
```
|
||||
=== "Python"
|
||||
```python
|
||||
previousNodeData = _("<node-name>").all();
|
||||
for item in previousNodeData:
|
||||
# item is of type <class 'pyodide.ffi.JsProxy'>
|
||||
# You need to convert it to a Dict
|
||||
itemDict = item.json.to_py()
|
||||
print(itemDict)
|
||||
```
|
||||
|
||||
@ -2,40 +2,58 @@
|
||||
contentType: reference
|
||||
---
|
||||
|
||||
# `$execution`
|
||||
# `execution`
|
||||
|
||||
## `$execution.id`
|
||||
## `execution.id`
|
||||
|
||||
Contains the unique ID of the current workflow execution.
|
||||
|
||||
```typescript
|
||||
const executionId = $execution.id;
|
||||
=== "JavaScript"
|
||||
```js
|
||||
let executionId = $execution.id;
|
||||
```
|
||||
=== "Python"
|
||||
```python
|
||||
executionId = _execution.id
|
||||
```
|
||||
|
||||
return [{json:{executionId}}];
|
||||
```
|
||||
|
||||
## `$execution.resumeUrl`
|
||||
## `execution.resumeUrl`
|
||||
|
||||
The webhook URL to call to resume a [waiting](/integrations/builtin/core-nodes/n8n-nodes-base.wait/) workflow.
|
||||
|
||||
See the [Wait > On webhook call](/integrations/builtin/core-nodes/n8n-nodes-base.wait/#webhook-call) documentation to learn more.
|
||||
|
||||
## `$execution.customData`
|
||||
## `execution.customData`
|
||||
|
||||
This is only available in the Code node.
|
||||
|
||||
```js
|
||||
// Set a single piece of custom execution data
|
||||
$execution.customData.set("key", "value");
|
||||
=== "JavaScript"
|
||||
```js
|
||||
// Set a single piece of custom execution data
|
||||
$execution.customData.set("key", "value");
|
||||
|
||||
// Set the custom execution data object
|
||||
$execution.customData.setAll({"key1": "value1", "key2": "value2"})
|
||||
// Set the custom execution data object
|
||||
$execution.customData.setAll({"key1": "value1", "key2": "value2"})
|
||||
|
||||
// Access the current state of the object during the execution
|
||||
const customData = $execution.customData.getAll()
|
||||
// Access the current state of the object during the execution
|
||||
var customData = $execution.customData.getAll()
|
||||
|
||||
// Access a specific value set during this execution
|
||||
const customData = $execution.customData.get("key")
|
||||
```
|
||||
// Access a specific value set during this execution
|
||||
var customData = $execution.customData.get("key")
|
||||
```
|
||||
=== "Python"
|
||||
```python
|
||||
# Set a single piece of custom execution data
|
||||
_execution.customData.set("key", "value");
|
||||
|
||||
# Set the custom execution data object
|
||||
_execution.customData.setAll({"key1": "value1", "key2": "value2"})
|
||||
|
||||
# Access the current state of the object during the execution
|
||||
customData = _execution.customData.getAll()
|
||||
|
||||
# Access a specific value set during this execution
|
||||
customData = _execution.customData.get("key")
|
||||
```
|
||||
|
||||
Refer to [Custom executions data](/workflows/executions/custom-executions-data/) for more information.
|
||||
|
||||
@ -7,7 +7,7 @@ hide:
|
||||
contentType: reference
|
||||
---
|
||||
|
||||
# `$getWorkflowStaticData(type)`
|
||||
# `getWorkflowStaticData(type)`
|
||||
|
||||
This gives access to the static workflow data.
|
||||
|
||||
@ -26,34 +26,64 @@ same in the whole workflow. Every node in the workflow can access it. The node s
|
||||
|
||||
Example with global data:
|
||||
|
||||
```javascript
|
||||
// Get the global workflow static data
|
||||
const workflowStaticData = $getWorkflowStaticData('global');
|
||||
=== "JavaScript"
|
||||
```javascript
|
||||
// Get the global workflow static data
|
||||
const workflowStaticData = $getWorkflowStaticData('global');
|
||||
|
||||
// Access its data
|
||||
const lastExecution = workflowStaticData.lastExecution;
|
||||
// Access its data
|
||||
const lastExecution = workflowStaticData.lastExecution;
|
||||
|
||||
// Update its data
|
||||
workflowStaticData.lastExecution = new Date().getTime();
|
||||
// Update its data
|
||||
workflowStaticData.lastExecution = new Date().getTime();
|
||||
|
||||
// Delete data
|
||||
delete workflowStaticData.lastExecution;
|
||||
```
|
||||
// Delete data
|
||||
delete workflowStaticData.lastExecution;
|
||||
```
|
||||
=== "Python"
|
||||
```python
|
||||
# Get the global workflow static data
|
||||
workflowStaticData = _getWorkflowStaticData('global')
|
||||
|
||||
# Access its data
|
||||
lastExecution = workflowStaticData.lastExecution
|
||||
|
||||
# Update its data
|
||||
workflowStaticData.lastExecution = new Date().getTime()
|
||||
|
||||
# Delete data
|
||||
delete workflowStaticData.lastExecution
|
||||
```
|
||||
|
||||
Example with node data:
|
||||
|
||||
```js
|
||||
// Get the static data of the node
|
||||
const nodeStaticData = $getWorkflowStaticData('node');
|
||||
=== "JavaScript"
|
||||
```js
|
||||
// Get the static data of the node
|
||||
const nodeStaticData = $getWorkflowStaticData('node');
|
||||
|
||||
// Access its data
|
||||
const lastExecution = nodeStaticData.lastExecution;
|
||||
// Access its data
|
||||
const lastExecution = nodeStaticData.lastExecution;
|
||||
|
||||
// Update its data
|
||||
nodeStaticData.lastExecution = new Date().getTime();
|
||||
// Update its data
|
||||
nodeStaticData.lastExecution = new Date().getTime();
|
||||
|
||||
// Delete data
|
||||
delete nodeStaticData.lastExecution;
|
||||
```
|
||||
// Delete data
|
||||
delete nodeStaticData.lastExecution;
|
||||
```
|
||||
=== "Python"
|
||||
```python
|
||||
# Get the static data of the node
|
||||
nodeStaticData = _getWorkflowStaticData('node')
|
||||
|
||||
# Access its data
|
||||
lastExecution = nodeStaticData.lastExecution
|
||||
|
||||
# Update its data
|
||||
nodeStaticData.lastExecution = new Date().getTime()
|
||||
|
||||
# Delete data
|
||||
delete nodeStaticData.lastExecution
|
||||
```
|
||||
|
||||
|
||||
|
||||
@ -3,18 +3,24 @@ description: Access your environment's custom variables.
|
||||
contentType: reference
|
||||
---
|
||||
|
||||
# `$vars`
|
||||
# `vars`
|
||||
|
||||
!!! info "Feature availability"
|
||||
* Available on Self-hosted Enterprise and Pro and Enterprise Cloud plans.
|
||||
* You need access to the n8n instance owner account to create variables.
|
||||
|
||||
`$vars` contains all [Variables](/variables/) for the active environment. It's read-only: you can access variables using `$vars`, but must set them using the UI.
|
||||
`vars` contains all [Variables](/variables/) for the active environment. It's read-only: you can access variables using `vars`, but must set them using the UI.
|
||||
|
||||
```js
|
||||
// Access a variable
|
||||
$vars.<variable-name>
|
||||
```
|
||||
=== "JavaScript"
|
||||
```js
|
||||
// Access a variable
|
||||
$vars.<variable-name>
|
||||
```
|
||||
=== "Python"
|
||||
```python
|
||||
# Access a variable
|
||||
_vars.<variable-name>
|
||||
```
|
||||
|
||||
!!! note "$vars and $env"
|
||||
`$vars` gives access to user-created variables. It's part of the [Environments](/source-control-environments/) feature. `$env` gives access to the [configuration environment variables](/hosting/environment-variables/environment-variables/) for your n8n instance.
|
||||
!!! note "vars and env"
|
||||
`vars` gives access to user-created variables. It's part of the [Environments](/source-control-environments/) feature. `env` gives access to the [configuration environment variables](/hosting/environment-variables/environment-variables/) for your n8n instance.
|
||||
|
||||
@ -3,7 +3,7 @@ description: How to use console.log() or print()
|
||||
contentType: howto
|
||||
---
|
||||
|
||||
# Using console.log or print in the Code node
|
||||
# Output to the browser console with `console.log()` or `print()` in the Code node
|
||||
|
||||
You can use `console.log()` or `print()` in the Code node to help when writing and debugging your code.
|
||||
|
||||
@ -30,3 +30,36 @@ For example, set your Code node **Language** to **Python**, copy the following c
|
||||
a = "apple"
|
||||
print(a)
|
||||
```
|
||||
|
||||
### Handling an output of `[object Object]`
|
||||
|
||||
If the console displays `[object Object]` when you print, check the data type, then convert it as needed.
|
||||
|
||||
To check the data type:
|
||||
|
||||
```python
|
||||
print(type(myData))
|
||||
```
|
||||
|
||||
#### JsProxy
|
||||
|
||||
If `type()` outputs `<class 'pyodide.ffi.JsProxy'>`, you need to convert the JsProxy to a native Python object using `to_py()`. This occurs when working with data in the n8n node data structure, such as node inputs and outputs. For example, if you want to print the data from a previous node in the workflow:
|
||||
|
||||
```python
|
||||
previousNodeData = _("<node-name>").all();
|
||||
for item in previousNodeData:
|
||||
# item is of type <class 'pyodide.ffi.JsProxy'>
|
||||
# You need to convert it to a Dict
|
||||
itemDict = item.json.to_py()
|
||||
print(itemDict)
|
||||
```
|
||||
|
||||
Refer to the Pyodide documentation on [JsProxy](https://pyodide.org/en/stable/usage/api/python-api/ffi.html#pyodide.ffi.JsProxy){:target=_blank .external-link} for more information on this class.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -641,7 +641,7 @@ nav:
|
||||
- Get number of items returned by last node: code/cookbook/code-node/number-items-last-node.md
|
||||
- Split binary file data into individual items: code/cookbook/code-node/split-binary-file-data.md
|
||||
- Get the binary data buffer: code/cookbook/code-node/get-binary-data-buffer.md
|
||||
- Using console.log: code/cookbook/code-node/console-log.md
|
||||
- Output to the browser console: code/cookbook/code-node/console-log.md
|
||||
- API:
|
||||
- api/index.md
|
||||
- Authentication: api/authentication.md
|
||||
|
||||
Loading…
Reference in New Issue
Block a user