> For AI agents: the complete Sanity documentation index is available at [https://www.sanity.io/docs/llms.txt](https://www.sanity.io/docs/llms.txt).

# Global document references

Why every document pointer in a workflow carries its location, and which resources a workflow may read and write.

> [!WARNING]
> Early access
> Workflows is in early access, built in public. Read [How early access works](https://www.sanity.io/docs/workflows/prerelease) before you rely on it.



A workflow’s definitions and instances [documents](https://www.sanity.io/docs/content-lake/documents) live in one place, but the content it governs often lives somewhere else: another [dataset](https://www.sanity.io/docs/content-lake/datasets), another [project](https://www.sanity.io/docs/platform-management/projects-organizations-and-billing), sometimes [Canvas](https://www.sanity.io/docs/canvas/introduction-to-canvas) or the [Media Library](https://www.sanity.io/docs/media-library/introduction). The engine stores each guard next to the content it protects. A normal [Sanity reference](https://www.sanity.io/docs/studio/reference-type) (`_ref`) only points within a single dataset, so it cannot cross that boundary. The engine works across a whole [organization](https://www.sanity.io/docs/platform-management/projects-organizations-and-billing), so everywhere it points at a document it uses a *global document reference*, a GDR: a reference that carries both which document and where it lives.

## Cross-resource coordination

A workflow can keep its data in one resource while the content it coordinates stays in others: editorial documents in another project, campaign assets in a Media Library. The workflow stores references rather than copies, so the content stays where its own editors and permissions already are. [Coordinate content across projects and datasets](https://www.sanity.io/docs/workflows/cross-resource-workflows) sets one up end to end: choosing the resources, binding aliases per environment, routing foreign resources to their own clients, and proving the routing before you rely on it.

## The GDR shape

A GDR is a small object, an `id` and a `type`:

```typescript
import {refDataset} from '@sanity/workflows'

// an article in the "production" dataset of project "yourprojectid"
const subject = refDataset({
  projectId: 'yourprojectid',
  dataset: 'production',
  documentId: 'article-1',
  type: 'article',
})
// → { id: 'dataset:yourprojectid:production:article-1', type: 'article' }
```

That `id` is not a bare document ID. Everywhere else in Sanity a reference is bare: a document’s `_id` or the `_ref` inside a reference, like `"article-1"`. A GDR’s `id` carries the resource prefix, because the engine has to know which project and dataset (or which Canvas, Media Library, or [Dashboard](https://www.sanity.io/docs/dashboard/dashboard-introduction) resource) holds the document. The scheme leads:

```typescript
// A GDR id is a typed URI:
//   dataset:<projectId>:<dataset>:<documentId>
//   canvas:<resourceId>:<documentId>
//   media-library:<resourceId>:<documentId>
//   dashboard:<resourceId>:<documentId>
export type GdrScheme = 'dataset' | 'canvas' | 'media-library' | 'dashboard'
export type GdrUri = `${GdrScheme}:${string}`
```

The `type` is the document’s [schema type](https://www.sanity.io/docs/studio/schema-types), carried so a reader knows what it points at without a second lookup.

Build one with the per-scheme constructors (`refDataset`, `refCanvas`, `refMediaLibrary`, `refDashboard`), and call `extractDocumentId` to get the bare `_id` back when you need it (for a `*[_id == $id]` query, for example). If you pass a bare ID where a GDR belongs, TypeScript rejects it, so an ID with no location can never reach a filter or a stored field. There is one deliberate exception: a literal `initialValue` seed in a definition may name a bare ID, and the engine roots it at the workflow resource when the instance resolves the field.

## Stable dataset document IDs

A dataset GDR identifies the logical document. Pass its stable ID, such as article-1. Do not pass drafts.article-1 or versions.<release>.article-1. The workflow perspective selects the draft, published document, or release version to read.

## Where global document references appear

You meet global document references wherever a workflow names a document: the subject passed at start, doc.ref and doc.refs fields, release.ref, and the ancestor chain. A start.filter reads the loaded candidate document. Start requirements read the caller-supplied input fields.

Compare global document references directly. Do not build resource-qualified strings yourself. Use a single-subject start requirement when only one unfinished instance of the same definition may exist for a subject. See Conditions for start filters, requirements, and their available values.

In conditions, the instance refers to itself as `$self`, its own GDR. That location-carrying `id` is also what lets a workflow read content it does not live next to: when a filter dereferences a subject in another dataset, the engine routes the read to a client for that GDR’s resource. A `resourceClients` resolver you give `createEngine` takes priority whenever it returns a client. Otherwise the engine derives a sibling client from the workflow client’s own credentials, with `withConfig`. A single-resource setup never notices any of this. A cross-dataset, cross-project, Media Library, Canvas, or dashboard setup works with no extra wiring, as long as the token can reach that resource. A client without `withConfig` cannot derive siblings, so a foreign GDR fails loudly instead of reading the wrong place.

The same shape flows into effects. When you bind a referenced id into an effect (`bindings: {assetId: '$fields.asset._id'}`), the value the handler receives is that document’s GDR URI. Turn it into a bare ID with `extractDocumentId`. And `$fields.asset._id` resolves from the stored reference itself, so identity reads never load the referenced document at all. Content reads (`$fields.asset.title`, for example) dereference into the loaded document, through the same client routing as a filter. Pass `resourceClients` when a resource needs different credentials.

The engine exposes GDRs directly because it is organization-wide by design. Writing a `doc.ref` value or wiring up `resourceClients` means working with GDRs explicitly.

## Allowed target resources

Reads and writes reach the same resources by default. An engine without `resourceClients` declares every resource its client can address: any dataset in any project, and any Media Library, Canvas, or dashboard. A ref into any of them can be stored and read. Pass `resourceClients` to narrow that set. The declared resources are then the workflow’s own resource plus every resource the resolver returns a client for. `deploymentResourceClients({client, deployment})` serves only the resources a deployment binds in `resourceAliases`, and `() => undefined` serves none. A resource the resolver leaves out is not a write target.

The engine checks refs that callers supply against that declared surface before they enter field state. A `doc.ref`, `doc.refs`, or `release.ref` value can arrive from a start `initialFields` value, an action’s param-sourced op value, an `editField` value, or an effect-completion op. It must target a declared resource. A ref to any other resource aborts the commit with `RefResourceUndeclaredError`, and nothing is written. Refs the deployed definition already carries are exempt, because deploy already checked them: literal `initialValue` seeds, `type: 'query'` texts, spawn `with` projections, and an op value built only from definition content, with no parameter or effect-output read. Like every engine check, this one is advisory, and the Content Lake is the only enforcement point. What it buys you is that a misdirected ref fails at the write that introduces it, rather than at a later read.

## What each resource type supports

A ref can point into any of the four resource types, but the platform offers different features in each. The engine follows what the resource type supports instead of assuming a dataset. Two kinds of resource matter here: the resource a ref points into, and the workflow resource, where the instance and its definition live.

This table lists what each resource type supports:

| Capability | Dataset | Media Library | Canvas | Dashboard |
| --- | --- | --- | --- | --- |
| Drafts and release versions | Yes | Yes | Yes | Yes |
| Content Releases | Yes | Yes | No | No |
| Document history | Yes | Yes | Yes | No |
| Grants for `$can` | Yes | Yes | Yes | No |
| Roles and members | Yes | Yes | No | No |
| Organization for `$attributes` | Yes | Yes | Yes | Yes |
| Sanity Functions triggers (`functionEvents`) | Yes | Yes, on `sanity.asset` documents only | No | No |

For a ref into another resource, the engine follows these capabilities when it reads:

- An effect’s `context.getDocument(ref)` follows the instance’s perspective in every resource type: the version in the instance’s releases first, then the draft when the perspective includes drafts, then the published document.
- `context.getDocument(ref, {at: 'rev'})` reads the bound revision from document history. On a dashboard, which keeps no document history, it throws `ResourceCapabilityError` with `capability: 'history'`.
- A `release.ref` value that names a release in a Canvas or dashboard is not a valid field value. A write throws `FieldValueShapeError`, and deploy rejects a literal seed that holds one.

For the workflow resource, the capabilities limit which definitions you can deploy there. Deploy throws `ResourceCapabilityError` before it writes anything when a definition needs a capability the workflow resource’s type lacks:

- `capability: 'grants'`: a condition reads `$can`, and the workflow resource is a dashboard.
- `capability: 'members'`: an assignment field declares `roles`, and the workflow resource is a Canvas or dashboard.
- `capability: 'roles'`: the definition names a role, or reads `$actor.roles`, and the workflow resource is a Canvas or dashboard. Roles can appear in `roles` on the start block, actions, fields, or `abort`, in `roleAliases`, or in a role assignee in a literal `initialValue`.

A definition that needs more than one missing capability reports the first in that order. The error’s `kind` is `resource-capability-unavailable`, and it carries `resourceType` and `capability`. The engine also refuses a definition already stored on a Canvas or dashboard that names or reads roles: `startInstance`, a spawn, `fireAction`, `editField`, and `tick` throw the same error before they evaluate any gate. `abortInstance` still runs.

The Workflows generator, `blueprints generate`, throws the same error with `capability: 'functionEvents'` when a generated Function would need a trigger on a Canvas or dashboard. That happens in two cases: the workflow resource is a Canvas or dashboard and its definitions need a Function, or a deployment that starts definitions autonomously binds a Canvas or dashboard as an alias. See [Predict when generated triggers run](https://www.sanity.io/docs/workflows/generate-functions).

## Next steps

- [Workflows](https://www.sanity.io/docs/workflows/introduction): the core model these references plug into.
- [Coordinate content across projects and datasets](https://www.sanity.io/docs/workflows/cross-resource-workflows): run one workflow over content in other resources, start to finish.
- [Deployments, partitions, and resources](https://www.sanity.io/docs/workflows/deployments-and-resources): how a deployment binds definitions to a resource and partition, and how aliases point them at real content.
- [Effects and runtimes](https://www.sanity.io/docs/workflows/effects-and-runtimes): how GDR-valued bindings reach effect handlers.
- [Reference](https://www.sanity.io/docs/workflows/reference): every construct spelled out exactly, each field, type, default, and option.

> [!NOTE]
> Visiting agent?
> Workflows has MCP tools that let an agent inspect, operate, author, validate, and deploy workflows. An agent host embeds these tools. Ask the person you work for whether your host [includes the Workflows tools](https://www.sanity.io/docs/workflows/mcp).





## Related changelog entries

Entries are listed newest first; each link points to the full entry as markdown. Follow one when you need to know what changed, when, or why — for example, to summarize recent updates, explain behavior that differs from older documentation, or check whether a fix has shipped.

- [Workflows v0.39.0: Four packages, start roles, and stricter checks](https://www.sanity.io/docs/changelog/workflows-MC4zOS4w.md) — November 16, 2026