@martmull v2.0 ;) --------- Co-authored-by: martmull <martmull@hotmail.fr> Co-authored-by: bosiraphael <raphael.bosi@gmail.com>
2.0 KiB
Workflows
Use when the app needs to ship a manual workflow on install, or when a logic function should be invocable from the workflow builder.
See logic.md for post-install hooks. See app-structure.md for source layout.
Mental Model
Twenty workflows are workspace records, not app entities — no define* primitive. Ship them via definePostInstallLogicFunction and the workspace API.
A workflow is a Workflow plus at least one WorkflowVersion. Creating a Workflow auto-creates its draft v1; never create a WorkflowVersion directly.
Manual Record Trigger
- Trigger type: manual record selection.
- The selected record is the trigger payload — no wrapping
recordfield. - Reference fields with
{{trigger.<field>}}. Do not use{{trigger.record.<field>}}.
Lifecycle
Always: create → configure draft → activate. Never publish a draft directly.
- Find or create the
Workflowby stable name or slug.createWorkflowproduces the draftv1. - Set the trigger on the draft via
updateWorkflowVersion. - Add steps via the workflow-step mutations.
createWorkflowVersionStepreturns astepsDiff, not the step — read the diff for the new step id, then callupdateWorkflowVersionStepwith the full payload. - Activate via
activateWorkflowVersion.
Forbidden:
- Do not write
Workflow.statuses— it is computed from the active version's status. - Do not create
WorkflowVersionrows directly.
Idempotency
Find by deterministic name or slug before creating. Single-record queries throw on absence in some Twenty versions — treat not-found as "needs create."
Permissions
Seeders need workflow settings permissions on the app role. Grant via defineRole. If a typed mutation is rejected from the app context, fix the role — falling back to raw GraphQL signals the wrong scope.
Invoking Locally
yarn twenty dev:function:exec
yarn twenty dev --once skips install hooks. Run again after rebuilding to verify idempotency.