From 8573b6513d53bc2575b13bb5bf7876dbd00909e2 Mon Sep 17 00:00:00 2001 From: Deborah Barnard Date: Mon, 27 Mar 2023 09:40:14 +0100 Subject: [PATCH] clarify static data behaviour and get/set node data --- .../get-workflow-static-data.md | 28 ++++++++++++++----- .../methods-variables-reference.md | 2 +- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/docs/code-examples/methods-variables-examples/get-workflow-static-data.md b/docs/code-examples/methods-variables-examples/get-workflow-static-data.md index 950bae804..f0d088500 100644 --- a/docs/code-examples/methods-variables-examples/get-workflow-static-data.md +++ b/docs/code-examples/methods-variables-examples/get-workflow-static-data.md @@ -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; ``` diff --git a/docs/code-examples/methods-variables-reference.md b/docs/code-examples/methods-variables-reference.md index 3d01b4785..d8b214425 100644 --- a/docs/code-examples/methods-variables-reference.md +++ b/docs/code-examples/methods-variables-reference.md @@ -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: |