跳至内容

getWorkflowStaticData(type)#

这提供了对静态工作流数据的访问。

实验性功能

  • 测试工作流时静态数据不可用。工作流必须处于活动状态并通过触发器或webhook调用才能保存静态数据。
  • 在高频工作流执行下,此功能可能表现不稳定。

您可以直接在工作流中保存数据。这些数据应该较小。

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

静态数据分为两种类型:全局和节点。全局静态数据在整个工作流中是相同的,工作流中的每个节点都可以访问它。节点静态数据是该节点独有的,只有设置它的节点才能再次检索它。

全局数据示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// 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
# 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
 9
10
11
// 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
# 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

模板和示例#

优云智算