Skip to content

自定义执行数据#

¥Custom executions data

你可以使用“代码”节点或 执行数据节点 在工作流中设置自定义数据。n8n 会在每次执行时记录此信息。你可以在筛选执行列表时使用此数据,或者在工作流中使用“代码”节点获取它。

¥You can set custom data on your workflow using the Code node or the Execution Data node. n8n records this with each execution. You can then use this data when filtering the executions list, or fetch it in your workflows using the Code node.

Feature availability

Custom executions data is available on:

  • Cloud: Pro, Enterprise
  • Self-Hosted: Enterprise, registered Community

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

¥Set and access custom data using the Code node

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

¥This section describes how to set and access data using the Code node. Refer to Execution Data node for information on using the Execution Data node to set data. You can't retrieve custom data using the Execution Data node.

设置自定义执行数据#

¥Set custom executions data

设置一条额外数据:

¥Set a single piece of extra data:

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

设置所有额外数据。此操作会覆盖本次执行的整个自定义数据对象。

¥Set all extra data. This overwrites the whole custom data object for this execution:

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

存在一些限制:

¥There are limitations:

  • 它们必须是字符串

¥They must be strings

  • key 的最大长度为 50 个字符。

¥key has a maximum length of 50 characters

  • value 的最大长度为 255 个字符。

¥value has a maximum length of 255 characters

  • n8n 最多支持 10 项自定义数据。

¥n8n supports a maximum of 10 items of custom data

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

¥Access the custom data object during execution

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

¥You can retrieve the custom data object, or a specific value in it, during an execution:

```js // 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
 6
 7
 8
 9
10
11
12
````

=== "Python"
	```python
	# 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");