自定义执行数据#
您可以通过代码节点或执 行数据节点为工作流设置自定义数据。n8n会在每次执行时记录这些数据,您可以在筛选执行列表时使用此数据,或通过代码节点在工作流中调用这些数据。
功能可用性
自定义执行数据适用于:
- 云版本:专业版、企业版
- 自托管版本:企业版、已注册社区版
使用代码节点设置与访问自定义数据#
本节介绍如何使用代码节点设置和访问数据。如需了解通过执行数据节点设置数据的方法,请参阅执行数据节点文档。注意无法通过执行数据节点检索自定义数据。
设置自定义执行数据#
设置单项额外数据:
| JavaScript | Python |
|---|---|
$execution.customData.set("key", "value"); | _execution.customData.set("key", "value"); |
设置所有额外数据。此操作将覆盖此执行中的所有自定义数据对象:
| JavaScript | Python |
|---|---|
$execution.customData.setAll({"key1": "value1", "key2": "value2"}) | _execution.customData.setAll({"key1": "value1", "key2": "value2"}) |
存在以下限制:
- 必须为字符串类型
key最大长度为 50 个字符value最大长度为 255 个字符- n8n 最多支持 10 项自定义数据
在执行期间访问自定义数据对象#
您可以在执行期间获取自定义数据对象或其特定值:
| JavaScript | Python |
|---|---|
// 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"); | # 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"); |