# Node Reference

> 本次运行中任何已执行节点的输出、上一个节点，以及串联工作流的入口点。

Source: https://docs.sommatic.ai/zh/expressions/reference/node-reference/

每个示例都在已部署的表达式引擎上、基于页面末尾的[示例上下文](#example-context)运行过。

## `$('Node label')`

函数 · `NodeAccessor` · 来源: `Sommatic AI expression engine`

```javascript
$(label)
```

`$` 是一个函数。它接收节点的标签（画布上显示的名称），返回一个访问器，指向该节点在本次运行中产生的输出。没有标签的节点按其 `node_id` 查找。只有已执行的节点才有输出；对于其他名称，访问器依然存在并返回空条目，因此读取结果为 `undefined`，而不会报错。

查找按文本进行：重命名节点会使所有读取它的表达式失效；两个节点标签相同时，以工作流中位置靠后的那个为准。请为节点设置简短、稳定且唯一的标签。

### 参数

- `label` (string, 必填): 节点的标签，须与原文完全一致（区分大小写和空格）。节点没有标签时，传入其 `node_id`。

### 返回

`NodeAccessor`: 包含以下成员的对象。

### 成员

| 签名 | 类型 | 说明 |
| --- | --- | --- |
| `$('X').item` | `{ json }` | 以条目形式表示的节点输出：`item.json` 即节点的返回内容。节点未执行时为 `{ json: {} }`。 |
| `$('X').first()` | `{ json }` | 与 `.item` 相同。 |
| `$('X').last()` | `{ json }` | 与 `.item` 相同（一个节点只产生一个条目）。 |
| `$('X').all()` | `list` | 包含该节点条目的列表；节点未执行时为空列表。 |
| `$('X').params` (保留) | `object` | 保留：不暴露该节点的配置；始终为 `{}`。 |
| `$('X').context` (保留) | `object` | 保留：始终为 `{}`。 |
| `$('X').isExecuted` | `boolean` | 节点已在本次运行中执行时为 `true`。 |

### 示例

```javascript
{{ $('Normalize input').item.json.correlation_id }}
```

结果 (string):

```json
"c-7f3a"
```

在图中任意下游节点读取 webhook 的请求体。

```javascript
{{ $('Webhook Receiver').item.json.body.email }}
```

结果 (string):

```json
"ana.perez@example.com"
```

```javascript
{{ $('Classify').item.json.confidence >= 0.8 }}
```

结果 (boolean):

```json
true
```

位于另一分支或尚未到达的节点。

```javascript
{{ $('Approval').isExecuted }}
```

结果 (boolean):

```json
false
```

读取未执行的节点得到 undefined，而不是报错。

```javascript
{{ $('Approval').item.json.decision }}
```

结果 (undefined):

```json
undefined
```

```javascript
{{ $('Classify').all().length }}
```

结果 (number):

```json
1
```

### 说明

- 节点的输出就是它通过端口返回的内容（信封中的 `data`），而非信封本身：`$('X').item.json.ok` 并不存在。
- 位于未执行分支上的节点不算错误。需要区分时请检查 `.isExecuted`，例如在 `flow.if` 之后。

在 JSONata 中: 不可用：在 JSONata 中，$ 和 $$ 表示上下文。请改用 JavaScript 表达式读取该节点。

## `$prevNode`

对象 · `object` · 保留 · 来源: `Sommatic AI expression engine`

> **保留.** 引擎不会传递上一个节点：目前始终为 `{ name: 'Start', runIndex: 0, outputIndex: 0 }`。

```javascript
$prevNode
```

用于描述路由到当前节点的那个节点。引擎不会传递它，因此它始终保存相同的固定值。要知道是哪个节点产生了输入，请用 `$('label')` 读取其输出并检查 `.isExecuted`。

### 成员

| 签名 | 类型 | 说明 |
| --- | --- | --- |
| `$prevNode.name` (保留) | `string` | 用于表示上一个节点的名称。目前始终为 `'Start'`。 |
| `$prevNode.runIndex` (保留) | `number` | 用于表示上一个节点的尝试序号。目前始终为 `0`。 |
| `$prevNode.outputIndex` (保留) | `number` | 用于表示它所使用的输出端口。目前始终为 `0`。 |

### 示例

```javascript
{{ $prevNode }}
```

结果 (object):

```json
{
  "name": "Start",
  "runIndex": 0,
  "outputIndex": 0
}
```

在 JSONata 中: `$$prevNode.name`

## `Chain entry point`

节点输出 · `{ …data, chain_context }` · 来源: `Sommatic AI expression engine`

```javascript
$('Chain Entry Point').item.json
```

通过 [`workflow.chain`](/zh/nodes/workflow.chain/) 被另一个工作流调用的工作流，从 [`workflow.trigger`](/zh/nodes/workflow.trigger/) 节点开始（此处命名为 `Chain Entry Point`；请换成节点实际的标签）。它的输出是调用方发送的 `data`（展开到顶层），外加标识调用方的 `chain_context`。紧跟在触发器之后的节点以 `$json` 读取它；之后的任何节点用 `$('Chain Entry Point')` 读取。

在串联的工作流中，`$execution.id` 是链的**根**运行的 id，因此消息和任务在所有工作流中显示相同的引用；`$execution.run_flow_instance_result_id` 是这一跳的 id。

### 成员

| 签名 | 类型 | 说明 |
| --- | --- | --- |
| `$('Chain Entry Point').item.json.<field>` | `any` | 调用方发送的 `data` 对象中的每个字段，位于顶层。 |
| `…chain_context.caller_flow_definition_id` | `string \| null` | 调用方工作流的定义 id。触发器的 `accepted_caller_ids` 会据此校验。 |
| `…chain_context.caller_flow_instance_id` | `string \| null` | 调用方运行的流程实例 id。 |
| `…chain_context.caller_flow_slug` | `string \| null` | 调用方工作流的 slug。 |
| `…chain_context.caller_node_id` | `string \| null` | 发起调用的 `workflow.chain` 节点的 `node_id`。 |
| `…chain_context.correlation_id` | `string` | 本次调用的 id（`chain-` + 20 个字符），每次调用都会重新生成。 |
| `…chain_context.root_flow_instance_result_id` | `string \| null` | 链的根运行的结果 id，在每一跳中都相同（它也是 `$execution.id`）。 |

### 示例

紧跟触发器之后：调用方发送的数据，位于顶层。

```javascript
{{ $json.order_id }}
```

结果 (string):

```json
"ord_1042"
```

```javascript
{{ $('Chain Entry Point').item.json.chain_context.caller_flow_slug }}
```

结果 (string):

```json
"order-intake"
```

编辑器会提示 `data`，但触发器会把调用方的字段展开到顶层：读取 `.data` 得到 undefined。

```javascript
{{ $('Chain Entry Point').item.json.data }}
```

结果 (undefined):

```json
undefined
```

```javascript
{{ $('Chain Entry Point').item.json.chain_context.correlation_id }}
```

结果 (string):

```json
"chain-7Hq2Lw9sKd3pXa1mZr4t"
```

链的根运行。

```javascript
{{ $execution.id }}
```

结果 (string):

```json
"fir-root-xxxx"
```

链中的这一跳。

```javascript
{{ $execution.run_flow_instance_result_id }}
```

结果 (string):

```json
"fir-hop-xxxx"
```

### 说明

- 标签 `Chain Entry Point` 只是示例：`$('…')` 接收为 `workflow.trigger` 节点设置的标签。
- 只有继续传递，`chain_context` 才会随之延续：`workflow.chain` 节点会为下一跳构建一个新的上下文，并自动向前携带根 id。

在 JSONata 中: `$$json.chain_context.caller_flow_slug`

## 示例上下文

示例基于以下数据运行：当前节点的输入（`$json`）、已运行的节点（`$(…)`）、本次运行的 ID 以及当前节点。时钟固定为 `2026-11-26T14:30:00.000Z`，服务器时区为 UTC，因此各页面中 `$now` 与 `$today` 的值都相同。

```json
{
  "$json": {
    "body": {
      "order_id": "ord_1042",
      "email": "ana.perez@example.com",
      "customer": {
        "name": "Ana Pérez",
        "segment": "gold"
      },
      "priority": "",
      "items": [
        {
          "sku": "A-100",
          "qty": 2,
          "price": 10.5
        },
        {
          "sku": "B-200",
          "qty": 0,
          "price": 4
        },
        {
          "sku": "C-300",
          "qty": 1,
          "price": 25
        }
      ],
      "tags": [
        "new",
        "web",
        "new"
      ],
      "created_at": "2026-11-25T09:15:00Z"
    },
    "headers": {
      "content-type": "application/json"
    },
    "query": {},
    "method": "POST"
  },
  "nodes": {
    "Webhook Receiver": "= $json",
    "Normalize input": {
      "correlation_id": "c-7f3a",
      "channel": "web"
    },
    "Classify": {
      "label": "billing",
      "confidence": 0.92
    }
  },
  "run": {
    "$flow_instance_result_id": "fir-xxxx",
    "$flow_instance_id": "fi-xxxx",
    "$flow_definition_id": "fd-xxxx",
    "$flow_version_id": "fv-xxxx",
    "$flow_slug": "order-intake"
  },
  "node": {
    "node_id": "node-notify",
    "label": "Notify customer"
  }
}
```

串联工作流的示例基于第二个上下文运行：一个由 `workflow.chain` 启动的工作流，其 `workflow.trigger` 节点的标签为 `Chain Entry Point`。

```json
{
  "$json": {
    "order_id": "ord_1042",
    "customer_email": "ana.perez@example.com",
    "amount": 46,
    "chain_context": {
      "caller_flow_definition_id": "fd-caller-xxxx",
      "caller_flow_instance_id": "fi-caller-xxxx",
      "caller_flow_slug": "order-intake",
      "caller_node_id": "node-chain-billing",
      "correlation_id": "chain-7Hq2Lw9sKd3pXa1mZr4t",
      "root_flow_instance_result_id": "fir-root-xxxx"
    }
  },
  "run": {
    "$flow_instance_result_id": "fir-hop-xxxx",
    "$flow_instance_id": "fi-hop-xxxx",
    "$flow_definition_id": "fd-billing-xxxx",
    "$flow_version_id": "fv-billing-xxxx",
    "$flow_slug": "billing-review",
    "$input": {
      "data": {
        "order_id": "ord_1042",
        "customer_email": "ana.perez@example.com",
        "amount": 46
      },
      "chain_context": {
        "caller_flow_definition_id": "fd-caller-xxxx",
        "caller_flow_instance_id": "fi-caller-xxxx",
        "caller_flow_slug": "order-intake",
        "caller_node_id": "node-chain-billing",
        "correlation_id": "chain-7Hq2Lw9sKd3pXa1mZr4t",
        "root_flow_instance_result_id": "fir-root-xxxx"
      }
    }
  },
  "node": {
    "node_id": "node-create-task",
    "label": "Create review task"
  }
}
```

示例运行所基于的编排器提交 31e874b.
