clarify static data behaviour and get/set node data

This commit is contained in:
Deborah Barnard
2023-03-27 09:40:14 +01:00
parent 455d1f8656
commit 8573b6513d
2 changed files with 22 additions and 8 deletions

View File

@@ -23,22 +23,36 @@ has changed and saves it, if necessary.
There are two types of static data, "global" and "node". Global static data is the
same in the whole workflow. Every node in the workflow can access it. The node static data is unique to the node. Only the node that set it can retrieve it again.
Example:
Example with global data:
```javascript
// Get the global workflow static data
const staticData = $getWorkflowStaticData('global');
// Get the static data of the node
const staticData = $getWorkflowStaticData('node');
const workflowStaticData = $getWorkflowStaticData('global');
// Access its data
const lastExecution = staticData.lastExecution;
const lastExecution = workflowStaticData.lastExecution;
// Update its data
staticData.lastExecution = new Date().getTime();
workflowStaticData.lastExecution = new Date().getTime();
// Delete data
delete staticData.lastExecution;
delete workflowStaticData.lastExecution;
```
Example with node data:
```js
// Get the static data of the node
const nodeStaticData = $getWorkflowStaticData('node');
// Access its data
const lastExecution = nodeStaticData.lastExecution;
// Update its data
nodeStaticData.lastExecution = new Date().getTime();
// Delete data
delete nodeStaticData.lastExecution;
```

View File

@@ -66,7 +66,7 @@ This includes:
| `$execution.id` | The unique ID of the current workflow execution. | :white_check_mark: |
| `$execution.mode` | Whether the execution was triggered automatically, or by manually running the workflow. Possible values are `test` and `production`. | :white_check_mark: |
| `$execution.resumeUrl` | The webhook URL to call to resume a workflow waiting at a [Wait node](/integrations/builtin/core-nodes/n8n-nodes-base.wait/). | :white_check_mark: |
| `$getWorkflowStaticData(type)` | View an [example](/code-examples/methods-variables-examples/get-workflow-static-data/). Static data isn't available when testing workflows. The workflow must be active and called by a trigger or webhook to save static data. This gives access to the static workflow data. | :white_check_mark: |
| `$getWorkflowStaticData(type)` | View an [example](/code-examples/methods-variables-examples/get-workflow-static-data/). Static data doesn't persist when testing workflows. The workflow must be active and called by a trigger or webhook to save static data. This gives access to the static workflow data. | :white_check_mark: |
| `$itemIndex` | The index of an item in a list of items. | :x: |
| `$prevNode.name` | The name of the node that the current input came from. When using the Merge node, note that `$prevNode` always uses the first input connector. | :white_check_mark: |
| `$prevNode.outputIndex` | The index of the output connector that the current input came from. Use this when the previous node had multiple outputs (such as an If or Switch node). When using the Merge node, note that `$prevNode` always uses the first input connector. | :white_check_mark: |