getWorkflowStaticData
This gives access to the static workflow data.
You can save data directly in the workflow. This data should be small.
As an example: you can save a timestamp of the last item processed from an RSS feed or database. It will always return an object. Properties can then read, delete or set on that object. When the workflow execution succeeds, n8n checks automatically if the data 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.
You can only use static data in the JavaScript Code node. The Python Code node doesn't provide it.
Example with global data:
// Get the global workflow static data
const workflowStaticData = $getWorkflowStaticData('global');
// Access its data
const lastExecution = workflowStaticData.lastExecution;
// Update its data
workflowStaticData.lastExecution = new Date().getTime();
// Delete data
delete workflowStaticData.lastExecution;Example with node data:
Templates and examples
Use a data table instead
Data tables store data inside n8n without a Code node, and they keep their data when you test a workflow.
To store a marker such as the last processed item in a data table:
Add a Data Table node at the start of your workflow, using the Get row operation to read the stored value.
Reference the value in later nodes with an expression, such as
{{ $('Get row').item.json.lastExecution }}.Add a second Data Table node at the end of your workflow, using the Upsert row operation to write the new value.
Unlike static data, you can't read data table values directly in an expression or in the Code node. Read the row with a Data Table node first, then reference that node's output.
Related resources
Last updated
Was this helpful?