# Generators

> New random identifiers.

Source: https://docs.sommatic.ai/en/expressions/reference/generators/

Each example was run against the deployed expression engine over the [example context](#example-context) at the end of the page.

## `$uuid`

Variable · `string` · Source: `uuid · v4`

```javascript
$uuid
```

A random UUID version 4, 36 characters in the `8-4-4-4-12` hexadecimal layout. It is a property, not a function: write `$uuid`, not `$uuid()`. Every read produces a new value, even twice in the same expression.

### Examples

```javascript
{{ $uuid }}
```

Result (string) · Random: a new value on every run:

```json
"d5d1221a-b9bc-4f05-ac90-de73b5841ca9"
```

```javascript
{{ 'msg-' + $uuid }}
```

Result (string) · Random: a new value on every run:

```json
"msg-c2e2e36c-61ac-46c7-8d1c-952afe5e313e"
```

### Errors

- `$uuid is not a function`: It was called as `$uuid()`. Remove the parentheses.

### Notes

- When several nodes need the same id, generate it once (for example in a `data.transform`) and read it from that node with `$('…')`.

In JSONata: `$$uuid`

## `$randomId`

Function · `string` · Source: `Link Loom SDK · utilities.generator.id`

```javascript
$randomId({ length, prefix })
```

Returns `prefix` followed by `length` random hexadecimal characters (`0-9`, `a-f`). Use it for human-friendly references; for a standard identifier use `$uuid`.

### Parameters

- `options` (object, required): Always pass an object, even an empty one: `$randomId()` without it fails.
- `options.length` (number, optional, default `15`): How many random characters (up to 512).
- `options.prefix` (string, optional, default `'id-'`): Text placed before them.

### Returns

`string`: `prefix` + `length` hexadecimal characters.

### Examples

```javascript
{{ $randomId({ length: 8, prefix: 'ord-' }) }}
```

Result (string) · Random: a new value on every run:

```json
"ord-70fb73b5"
```

```javascript
{{ $randomId({}) }}
```

Result (string) · Random: a new value on every run:

```json
"id-fe83456fd23b165"
```

Without the options object it fails.

```javascript
{{ $randomId() }}
```

Throws:

```text
Cannot destructure property 'length' of 'undefined' as it is undefined.
```

### Errors

- `Cannot destructure property 'length' of 'undefined' as it is undefined.`: It was called without the options object. Pass `{}` at least.

In JSONata: `$$randomId({ "length": 8, "prefix": "ord-" })`

## Example context

The examples run over this data: the input of the current node (`$json`), the nodes that already ran (`$(…)`), the ids of the run and the current node. The clock is fixed at `2026-11-26T14:30:00.000Z` and the server zone is UTC, so `$now` and `$today` give the same values on every page.

```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"
  }
}
```

The examples of a chained workflow run over a second context: a workflow started by `workflow.chain`, whose `workflow.trigger` node is labelled `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"
  }
}
```

Examples run against the orchestrator at commit 31e874b.
