跳至内容

自定义执行数据#

您可以使用代码节点或执行数据节点在工作流上设置自定义数据。n8n会记录每次执行的这些数据。之后您可以在筛选执行列表时使用这些数据,或者通过代码节点在工作流中获取它们。

功能可用性

自定义执行数据可在以下位置获取:

  • 云版本:专业版、企业版
  • 自托管:企业版、已注册社区版

适用于版本0.222.0及以上。

使用代码节点设置和访问自定义数据#

本节介绍如何使用代码节点设置和访问数据。有关使用执行数据节点设置数据的信息,请参阅执行数据节点。您无法使用执行数据节点检索自定义数据。

设置自定义执行数据#

设置一条额外的数据:

1
$execution.customData.set("key", "value");
1
_execution.customData.set("key", "value");

设置所有额外数据。这将覆盖此执行中的整个自定义数据对象:

1
$execution.customData.setAll({"key1": "value1", "key2": "value2"})
1
_execution.customData.setAll({"key1": "value1", "key2": "value2"})

存在以下限制:

  • 它们必须是字符串
  • key 的最大长度为50个字符
  • value 的最大长度为255个字符
  • n8n 最多支持10项自定义数据

在执行期间访问自定义数据对象#

你可以在执行过程中检索自定义数据对象,或其中的特定值:

1
2
3
4
5
// Access the current state of the object during the execution
const customData = $execution.customData.getAll();

// Access a specific value set during this execution
const customData = $execution.customData.get("key");
1
2
3
4
5
# Access the current state of the object during the execution
customData = _execution.customData.getAll();

# Access a specific value set during this execution
customData = _execution.customData.get("key");
优云智算