Skip to content

getWorkflowStaticData(type)#

这将允许你访问静态工作流数据。

¥This gives access to the static workflow data.

Experimental feature

  • 测试工作流时,静态数据不可用。工作流必须处于活动状态,并且由 trigger 或 Webhook 调用才能保存静态数据。

¥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 feature may behave unreliably under high-frequency workflow executions.

你可以直接在工作流中保存数据。此数据量应该很小。

¥You can save data directly in the workflow. This data should be small.

作为示例:你可以保存 RSS 源或数据库中最后处理项目的时间戳。它始终返回一个对象。然后,可以读取、删除或设置该对象的属性。工作流执行成功后,n8n 会自动检查数据是否已更改,并在必要时保存。

¥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.

包含全局数据的示例:

¥Example with global data:

```javascript // 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;

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
````

=== "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
1
2
3
4
5
6
7
8
包含节点数据的示例:

¥Example with node data:

=== "JavaScript"
	```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;

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
````

=== "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
````

模板和示例#

¥Templates and examples

Workflow preview placeholder.