本页内容
Sommatic 文档
打开控制台

Generators

新生成的随机标识符。

以 Markdown 查看
在以下应用中打开

每个示例都在已部署的表达式引擎上、基于页面末尾的示例上下文运行过。

$uuid

$uuid

随机的第 4 版 UUID,36 个字符,采用 8-4-4-4-12 的十六进制格式。它是属性而非函数:写 $uuid,不要写 $uuid()。每次读取都产生新值,即使在同一表达式中读取两次也是如此。

示例

{{ $uuid }}
结果 string 随机:每次运行都会生成新值
"d5d1221a-b9bc-4f05-ac90-de73b5841ca9"
{{ 'msg-' + $uuid }}
结果 string 随机:每次运行都会生成新值
"msg-c2e2e36c-61ac-46c7-8d1c-952afe5e313e"

错误

消息 原因与解决方法
$uuid is not a function 以 $uuid() 的形式调用了它。请去掉括号。

说明

  • 多个节点需要同一个 id 时,只生成一次(例如在 data.transform 中),再用 $('…') 从该节点读取。

在 JSONata 中 $$uuid

$randomId

$randomId({ length, prefix })

返回 prefix 加上 length 个随机十六进制字符(0-9、a-f)。适用于便于人工识读的引用编号;标准标识符请使用 $uuid。

参数

options object 必填
务必传入一个对象,即使是空对象:不传则 $randomId() 会失败。
options.length number 可选 默认 15
随机字符的个数(最多 512)。
options.prefix string 可选 默认 'id-'
放在随机字符前面的文本。

返回

string prefix + length 个十六进制字符。

示例

{{ $randomId({ length: 8, prefix: 'ord-' }) }}
结果 string 随机:每次运行都会生成新值
"ord-70fb73b5"
{{ $randomId({}) }}
结果 string 随机:每次运行都会生成新值
"id-fe83456fd23b165"

不传选项对象会失败。

{{ $randomId() }}
抛出
Cannot destructure property 'length' of 'undefined' as it is undefined.

错误

消息 原因与解决方法
Cannot destructure property 'length' of 'undefined' as it is undefined. 调用时没有传选项对象。至少传入 {}。

在 JSONata 中 $$randomId({ "length": 8, "prefix": "ord-" })

示例上下文

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

当前节点的输入 JSON
{
  "$json": {
    "body": {
      "order_id": "ord_1042",
      "email": "[email protected]",
      "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"
  }
}
已运行的节点(标签 → 输出) JSON
{
  "Webhook Receiver": "= $json",
  "Normalize input": {
    "correlation_id": "c-7f3a",
    "channel": "web"
  },
  "Classify": {
    "label": "billing",
    "confidence": 0.92
  }
}
运行与当前节点 JSON
{
  "$execution": {
    "id": "fir-xxxx",
    "flow_instance_id": "fi-xxxx",
    "flow_definition_id": "fd-xxxx",
    "flow_version_id": "fv-xxxx",
    "flow_slug": "order-intake"
  },
  "$node": {
    "id": "node-notify",
    "label": "Notify customer"
  }
}

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

安装智能体工具

为你的编程智能体接入 Sommatic AI 官方文档:技能包、文档 MCP 服务器与 Markdown 页面,无需再抓取网页。

仅安装技能包,不会自动更新;需要时重新运行即可。

npx skills add https://docs.sommatic.ai
智能体如何读取本文档