Skip to content

自定义执行数据

您可以使用代码节点或执行数据节点在工作流中设置自定义数据。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"})

存在以下限制:

  • 它们必须是字符串
  • 最大长度为 50 个字符
  • 最大长度为 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");