# Instructions for Fluent PlaybookDefinition API
Always reference the PlaybookDefinition API specifications for more details.
1. Import `PlaybookDefinition`, `wfa`, `PlaybookTriggerTypes`, and `ActivityDefinitions` from `@servicenow/sdk/automation`. Import Column types (`ReferenceColumn`, `IntegerColumn`, `StringColumn`, etc.) for inputs/outputs from `@servicenow/sdk/core`.
2. Use a Playbook to model a **guided, record-driven multi-step process** (lanes of activities a fulfiller works through). It is distinct from a Flow: playbooks are interactive and operate on a parent record.
3. Call `PlaybookDefinition(config, dependentConfig, body)` with **three arguments**. `config` holds top-level properties plus declarative `inputs`/`outputs`; argument 2 is the dependent config object — not just triggers — carrying `triggers`, the optional `permissions` callback (SDK v4.11.0+), and the optional `variants` callback (SDK v4.13.0+); `body` is `{ lanes: (params) => ({...}) }`.
4. In `config`, `$id` (use `Now.ID['...']`) and `label` are mandatory. Set `parentTable` to the table the playbook runs on — this auto-creates a `parent_record` input exposed as `params.parentRecord` (dot-walkable to fields). Treat `name` as stable identity: don't change it after deploy, or the platform creates a new record instead of updating.
5. The `triggers` array is **required even when empty** — pass `{ triggers: [] }` for a playbook with no triggers. Build each trigger with `wfa.playbook.trigger(triggerType, config, triggerInputs, playbookInputs?)`. Choose `triggerType` from `PlaybookTriggerTypes` (`RecordCreate`, `RecordUpdate`, `RecordCreateOrUpdate`, `Scheduled`).
6. Trigger inputs differ by type: record-based triggers take `{ table, condition?, runTriggerOnExtendedTables? }`; scheduled triggers take `{ table, condition?, limit (1-1000), startDateAndTime, timeZone? }` plus schedule-type fields. Use the optional 4th `playbookInputs` arg only when the playbook declares inputs or the trigger table differs from `parentTable`; wrap record references in `wfa.playbook.dataPill(trigger.current...)` and use plain values for literals.
7. `body.lanes` **must be a callback** `(params) => ({...})` — the build transformer reads lane/activity keys statically from the arrow-function body, not from a plain object. Build lanes with `wfa.playbook.lane({ config, activities })`, where `config` is a plain `LaneConfig` and `activities` is another `(params) => ({...})` callback. Inside `activities`, use `const` bindings and an explicit-key `return { name: name }` so keys are statically extractable.
8. Every lane and activity config requires `$id`, `label`, `order`, `startRule`, and `restartRule`. Set execution order with `startRule`: `wfa.playbook.run.Immediately()` for no dependencies, or `wfa.playbook.run.After(...deps)` (varargs, not an array) to wait for activities, lanes, or decision branches. `order` controls only visual layout. `restartRule` is `'RUN_ALWAYS'`, `'RUN_ONLY_ONCE'`, or `'RUN_ONLY_ON_RESTART'`.
9. Create activities with `wfa.playbook.activity(definition, config, inputs?, experienceProperties?)` using definitions from `ActivityDefinitions.Core.*` (e.g. `UpdateRecord`, `CreateNewRecord`, `SendEmail`, `Instruction`, `Decision`). Pass automation inputs in the 3rd arg and UI configuration in the 4th. Reference runtime data with `wfa.playbook.dataPill(...)` and field templates with `TemplateValue({...})`.
10. For branching, use `ActivityDefinitions.Core.Decision` with inputs `{ type: 'match_first' | 'match_all', branches: [...] }`. Each branch needs `id`, `label`, and (except the `else` branch) a `condition`. The `else` branch must be **last** with `id: 'else'`, `label: 'Else'`, and no condition. Depend on a branch via `wfa.playbook.run.After(decision.branches.<id>)`. A branch may also set `isIdealPath` (SDK v4.13.0+) — see item 30.
11. `outputs` declares the playbook's output schema; write values into it from the DSL with the `ActivityDefinitions.Core.SetPlaybookOutputs` activity (SDK v4.11.0+, see item 22) — you do not need Playbook Designer for that.
12. Remember: deploying a playbook does **not** update already-running instances. Open Playbook Designer and re-activate the playbook to apply changes at runtime (the build output logs this reminder).
13. **SDK v4.11.0** — argument 2's type was renamed from `PlaybookTriggerDeclaration` to `PlaybookDependentConfig<I, P, E>`; the old name no longer exists in the package. If you import that type by name, update it. Its shape now depends on argument 1 — the `inputs` schema, `parentTable`, and `executionType` all flow into it — and it carries `permissions` in addition to `triggers`.
14. **SDK v4.11.0** — `executionType` widened to `'record_driven' | 'on_demand'`. Choose `'on_demand'` (standalone) only when the playbook is started explicitly rather than by a record trigger, and know that **six things change at once**: omit `triggers` entirely (not even `[]`), do not set `parentTable`, do not reference `params.parentRecord` anywhere in `lanes` or `permissions`, do not set the launcher record-form fields, `allowAsNested` may finally be `true`, and **at least one permission set must grant `launch: true`** — that last one fails the build even when `permissions` is omitted altogether. All six are enforced as both a type error and a build diagnostic.
15. **SDK v4.11.0** — the launcher fields are counterintuitive, so read this before using them: `launcherShowRecordForm`, `launcherRecordFormView`, and `launcherTemplateFields` are **forbidden** on an `'on_demand'` playbook despite being called "on-demand launcher" configuration. They pre-populate a `parentTable` record, and `parentTable` is itself forbidden there — so they belong to launching a **record-driven** playbook on demand. Only `launcherTitle`, `launcherDescription`, and `launcherInputs` are legal on a standalone playbook.
16. **SDK v4.11.0** — launcher field rules: set `launcherShowRecordForm: true` **first**, because using either of the other two record-form fields without it is a build error. `launcherRecordFormView` stores the view's **sys_id**, not its display name — `'Default view'` is a special-case string that works as-is, but any other view must be passed by real sys_id (or a typed `Record<'sys_ui_view'>`); the SDK cannot resolve a display name or verify the view exists. In `launcherInputs`, pass a **string** for every non-reference input including booleans and integers (`'true'`, `'3'`) — a raw literal does not compile — and remember it only changes what the launcher *displays*, never the input's own `default`.
17. **SDK v4.11.0** — permissions come in two flavours that are **not** interchangeable. Playbook-level `permissions` (argument 2) is a **callback** `(params) => ({...})` so pills can reach `params.parentRecord`; lane-level `permissions` (on `LaneConfig`) is a **plain object**. Playbook flags are `view`, `launch`, `laneAddOptionalActivity`, `restart`, `laneRestart`, `activityRestart`, `cancel`; lane flags are the reduced set `view`, `addOptionalActivity`, `restart`, `activityRestart`.
18. **SDK v4.11.0** — `view` behaves differently at the two levels, and this is the easiest permission mistake to make. On a **playbook** permission set `view` is **required and gates every other flag** — another flag without `view: true` on that same set is a build error and grants nothing. On a **lane** permission set all four flags are **independent and optional**; `view` gates nothing. Group each reference under the right kind (`users`/`userGroups`/`roles`/`userCriterias`) and list each reference once.
19. **SDK v4.11.0** — reference forms differ by level too. At the playbook level `user`/`userGroup` are normally data pills, and a bare sys_id string is only valid when `executionType` is not `'record_driven'`. At the lane level `user`/`userGroup` must be data pills; only `role` and `userCriteria` accept a bare sys_id string.
20. **SDK v4.11.0, widened in SDK v4.13.0** — `wfa.playbook.activityRef(Now.ID['x'])` references an activity by `$id` (it need not be in lexical scope) and is valid in exactly three contexts: (a) inside `wfa.playbook.dataPill()` in playbook and lane `permissions`, outputs only; (b) inside `wfa.playbook.dataPill()` in a variant `condition`, only when `evaluateVariantChildrenAfter` is set and only for activities that run strictly before that activity (item 28); (c) as a `run.After()` dependency inside a `variantOverrides` entry's `startRule`, to forward-reference an activity declared later in the same lane (item 27). It is **not** accepted in a normal lane or activity `startRule` — that is a type error. Prefer the ordinary local or lane variable wherever it is visible.
21. **SDK v4.11.0** — optional activities: pass `startRule: wfa.playbook.run.Manually()` for an activity a user starts by hand at runtime (Playbook Designer calls it "optional"). Its config is narrower — omit `order`, `conditionToRun`, and `startWithDelay` — and, since SDK v4.13.0, also `variant` and `variantOverrides`, because optional activities exist only at the base playbook level — and pin `restartRule: 'RUN_ONLY_ONCE'`. An optional activity also cannot be the `evaluateVariantChildrenAfter` target or a Go Back target. **The call returns a `ManualActivityReference` with no outputs, deliberately outside the `Dependency` union**: because an optional activity may never run, nothing may reference its outputs or wait on it with `run.After()`. Do not design a dependency chain through one.
22. **SDK v4.11.0** — `ActivityDefinitions.Core.SetPlaybookOutputs` writes the playbook's own declared `outputs`. Its single authored input is `playbook_outputs`, a `TemplateValue` keyed by the playbook's `outputs` names. Do not attempt to set `playbook_outputs_var_table_name` — the plugin derives it from the containing playbook and it is deliberately hidden from the DSL.
23. **SDK v4.11.0** — AI-agent activity configuration is available **only** on definitions declaring `enableAiAgent: 'on'`, which in this release means exactly four OOB definitions: `RecordForm`, `AutocompletingRecordForm`, `NewRecordForm`, and `EmailForm` (`AutocompletingRecordForm` exposes a reduced field set). Setting any AI field on any other definition is a TypeScript error. `aiAgentObjective` is required once `enableAiAgent` is true — omitting it or passing `''` is a build error. `aiAgentExecutionMode: 'on'` (Autonomous) is a build error unless the definition itself declares it, and `aiAgentObjAdditionalDetail` set while the mode is not `'on'` is a warning whose value is silently discarded. The SDK validates none of the platform prerequisites: the `sn_genai_platform` store app must be installed and `sn_pa_designer.enable_agentic_playbooks` must be `true`, or the configuration has no runtime effect. Still exactly these four in SDK v4.13.x: `Decision` and `GoBack` expose no AI fields, and since SDK v4.13.0 setting `enableAiAgent: true` on any activity of a `publicAccess: true` playbook is a build error (item 31). **SDK v4.14.0:** `enableAiAgent`, `aiAgentObjective`, `aiAgentExecutionMode` and `aiAgentRunAs` are always settable on an AI-capable definition, even when its `aiAgentFieldDisplayPreferences` omits them (this matters only for custom definitions; the four OOB ones already expose them). Never author `aiAgentUser` (internal and deprecated). Set the other AI fields only together with `enableAiAgent: true`: otherwise the platform ignores them with no build warning.
24. **SDK v4.11.0** — `schemaVersion` is now a public property rather than internal, and its ceiling is **instance-dependent**: Australia and older releases cap at 3, Brazil and newer also accept 4. Set `4` explicitly only after confirming the target instance's `com.glide.pad.core.model.maxSupportedSchemaVersion` system property — do not infer the ceiling from the release name. Leave it unset to take Fluent's safe fallback.
25. **SDK v4.11.0** — dependent record inputs are now type-checked: `UpdateRecord` and `CreateNewRecord` preserve `rawInputs`, so a `record` pill must match the table named in the sibling `table_name` input (a `sys_user` `UpdateRecord` rejects an `incident` pill at compile time), and `RecordForm`'s `associated_record` is checked against `associated_table` the same way. Keep the table and the pill in agreement rather than casting past the error. `SendEmail` also gained `to_email_address`, `cc_email_address`, and `bcc_email_address` inputs.
26. **SDK v4.13.0** — variants let one playbook take a different path per condition. Declare them in argument 2 as `variants: (params) => ({ ... })` built with `wfa.playbook.variant({ $id, label, condition, order, name?, description?, color?, parentVariant? })` (records in `sys_pd_process_variant`), and reference them from activities as `params.variants.<name>`. `condition` (an encoded query; pills may use `params.inputs`/`params.parentRecord`) and `order` are required, and an empty `condition` or `label` is a build error. `color` is one of `'blue'`, `'brown'`, `'green'`, `'magenta'`, `'orange'`, `'purple'`, `'teal'`, `'yellow'` and is auto-assigned from `$id` when omitted. `parentVariant` nests a variant under a sibling declared in the same callback — pass the sibling's **local identifier**, not `params.variants`. Evaluation is top-down: at each level the first child (lowest `order`) whose condition is true wins, and a child is only evaluated if its parent matched. Declaring any variant **requires `parentTable`** (build error); declaring variants with no lanes is a warning.
27. **SDK v4.13.0** — an activity takes part in variants in one of two **mutually exclusive** ways; never set both on one activity (a type error plus a build error). Use `variant: params.variants.<name>` for a **variant-only** activity that exists only when that variant is selected (`sys_pd_activity.variant`). Use `variantOverrides: [{ variant, startRule?, order? }]` on a **base** activity to change only its `startRule` and/or `order` for a variant (`sys_pd_activity_override`) — nothing else (inputs, label) can be overridden. One entry per variant (a duplicate is an error); an entry with neither `startRule` nor `order` is a no-op warning. Only activities can be variant-scoped; lanes cannot. To wait on an activity declared later in the same lane, write `run.After(wfa.playbook.activityRef(Now.ID['later']))` inside the override, and if an override reverses a base edge, override the other activity too or the two deadlock. Do **not** copy the first example in the SDK's "playbook-activities-guide" section on variant overrides: it uses a const before its declaration and fails with TS2448.
28. **SDK v4.13.0** — `evaluateVariantChildrenAfter: Now.ID['act_x']` (config) delays variant selection until that activity completes instead of evaluating at playbook start. It accepts only a `Now.ID` reference (a string literal is a type error), must name an **activity** (not a lane) that is not an optional activity, and needs at least one declared variant. Once set: a variant `condition` may read `activityRef()` outputs of activities that run **strictly before** that activity — the evaluation-point activity itself is rejected; every variant-only activity must be a guaranteed descendant of it; and a Go Back whose decision runs after it must also target something after it (error "Select a target after the variant evaluation point").
29. **SDK v4.13.0** — `ActivityDefinitions.Core.GoBack` restarts the playbook at an earlier activity, stage, or the start. It is valid **only as the terminal activity of a `'match_first'` decision branch**, reached through its own `run.After()` chain — never as a plain lane activity. Inputs are a discriminated union on `target_type`: `'go_back_to_target_activity'` with `go_back_to_target_activity`, `'go_back_to_target_stage'` with `go_back_to_target_stage`, or `'start_of_playbook'` with no target. Pass the raw lane/activity variable, not a data pill. Build errors: more than one Go Back per branch, parallel paths in the branch, anything running after it, a target that does not precede the decision (or is optional, or another Go Back), and every branch ending in a Go Back (keep at least one forward path, usually `else`). Give the target `restartRule: 'RUN_ALWAYS'` — otherwise it is only a **warning** and the target is silently skipped on the jump back — and use `restartable: 'RESTARTABLE_TRUE'` for `'start_of_playbook'`. The build cannot prove the loop ends: something on the re-run must be able to change the decision. Its config has no AI fields. Requires Process Automation Designer (`sn_pa_designer`) 29.3.0+.
30. **SDK v4.13.0** — `isIdealPath` on a Decision branch marks the "golden path" Playbook Designer highlights (default false). A `'match_first'` decision allows at most one ideal branch; `'match_all'` allows several; `else` may be ideal but not together with a conditional branch — all build errors. Requires `sn_pa_designer` 29.6.4+; on older versions the flag is written but ignored.
31. **SDK v4.13.0** — `publicAccess: true` (config) is **not** a public API, and it is unrelated to `access`, which only controls cross-scope visibility. It sets the playbook's public-access flag so it can be **embedded on public pages and run by unauthenticated users**. Rules: `parentTable` is required; it cannot be set on `'on_demand'` playbooks (typed never); every activity must come from a definition declaring `publicAccess: true` — public-safe built-ins are `Instruction`, `TwoStepInstruction`, `RecordForm`, `AutocompletingRecordForm`, `NewRecordForm`, `KnowledgeArticle`, `Placeholder`, `WaitForCondition`, `SetPlaybookOutputs`, `Decision`, and `GoBack`, but not `SendEmail`, `EmailForm`, `UpdateRecord`, `CreateNewRecord`, `ChecklistTask`, `RecordList`, `NewRecordFormWithList`, or the approval definitions (the type error is reported on the lane/body entry, not the activity call); and no activity may set `enableAiAgent: true`. Serving it publicly still needs a public page/experience and guest access configured outside Fluent, and editing it in Playbook Designer needs the `playbook.write.public_access` role. A custom `ActivityDefinition()` opts in with `publicAccess: true`. Requires `sn_pa_designer` 29.0.0+.
32. **SDK v4.13.0** — `actionOverrides: [{ actionAssignment, label, displayOrder }]` is set **per activity** (not per playbook) and writes one `sys_pd_activity_action_override` per entry. When present it **replaces** the Playbook Card's default Declarative Action buttons with exactly that list rather than merging; omit it to keep the defaults. `actionAssignment` is the sys_id (or a `Record<'sys_declarative_action_assignment'>`) of a `sys_declarative_action_assignment` row — platform data looked up on the instance, not authored in Fluent. A missing/empty `actionAssignment`, duplicate assignments, and duplicate `displayOrder` values are only warnings. Requires `sn_pa_designer` 29.4+.
33. **SDK v4.13.0** — `wfa.playbook.automationPlan(uiId?)` inside `wfa.playbook.dataPill()` references an input or output of the activity's **own** backing flow/action (`automationPlan().outputs.record`, `automationPlan().inputs.table`). It is allowed **only in experience properties** — the `Activity()` 4th argument or an `ActivityDefinition()`'s `defaultExperienceProperties`; in activity inputs, conditions, or `startWithDelay` it is a build error. `uiId` must be a string literal naming a step of a Subflow-backed definition (an error on an Action-backed one), and the path must continue with `.inputs` or `.outputs`.
34. **SDK v4.13.0 — potentially BREAKING** — mandatory backing inputs are now validated at build time: the effective value (explicit, else the definition default) must not be empty, an explicit `''` beats the default and fails, and a data pill never counts as empty. `NewRecordForm` now **requires `table`** and has no default, so a `NewRecordForm` without `table` that built on SDK v4.11 now fails. `ChecklistTask` `checklist_items` is also mandatory, but its default fills an omitted value. The TypeScript signature still shows both as optional — only the build catches it. No built-in activity type has a mandatory experience property, so that half only affects custom activity types.
35. **SDK v4.13.0** — image attachments are **not** an authoring feature and are not on activities: `preservedAttachment` in argument 2 is framework-managed. It is filled in automatically when an existing playbook that already has an image attachment (e.g. a Now Assist-generated one) is transformed, so the image survives round trips. Never write or edit it by hand.
36. **SDK v4.13.0** — `BaseActivityConfig` changed from an interface to a type alias (an object intersected with the variant union), so "interface X extends BaseActivityConfig" now fails with TS2312; use an intersection type instead.
37. **SDK v4.13.0** — the playbook type definitions carry no "@since" tags, so you cannot tell from the types which SDK version introduced a property; rely on these instructions. The only version markers are Process Automation Designer (`sn_pa_designer`) minimums, none checked by the SDK: `publicAccess` 29.0.0, `GoBack` 29.3.0, `actionOverrides` 29.4, `isIdealPath` 29.6.4.
