defineWorkflow() call describes one workflow: a trigger and the steps it runs. On install, Twenty creates it as an active workflow in the workspace, ready to run.
Define a workflow
This workflow runs when a company is created. It calls one of the app’s logic functions, then writes the result on the company:src/workflows/score-new-companies.ts
- The workflow, its trigger and each step need their own
universalIdentifier. Keep them stable across releases: they are how Twenty matches the installed workflow on the next install. nextStepIdswires the graph. The trigger points to the first steps, and each step points to the steps that run after it.- A step reads earlier output with
{{trigger.<path>}}or{{<step universalIdentifier>.<path>}}. - The build validates the whole definition: unsupported trigger or step types, broken step links and references to unknown steps fail it.
Referencing other entities
Steps and triggers point at metadata by universal identifier, never by name or id:- Objects and fields: your app’s own, or standard ones through
STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS. The example above assumes the app also defines aleadScorenumber field on Company withdefineField(): a record step that writes a field missing from the workspace fails the install. - Logic functions: your app’s own, exposed as a workflow action with
workflowActionTriggerSettings. - Agents: your app’s own, from
defineAgent().
Triggers
A manual workflow without
availability gets no command menu entry.
A webhook workflow listens on https://<your-twenty-domain>/webhooks/workflows/<workspaceId>/<workflowId>, where workflowId is the id of the installed workflow. The request body is available as {{trigger.<path>}}.
Steps
Application workflows support these step types:LOGIC_FUNCTION, AI_AGENT, HTTP_REQUEST, CLASSIFY, CREATE_RECORD, UPDATE_RECORD, UPSERT_RECORD, DELETE_RECORD, FIND_RECORDS, PICK_RECORD, FILTER, IF_ELSE, ITERATOR, FORM, DELAY, WAIT_FOR_EVENT and EMPTY.
Their inputs match the steps of the workflow builder, with universal identifiers in place of names:
- Record steps take
objectUniversalIdentifierinstead of an object name. - Filters and sorts point at fields with
fieldMetadataUniversalIdentifier. - To run your own code, use a
LOGIC_FUNCTIONstep. The builder’s Code step is not available, and neither are the email and calendar steps.
After install
- The workflow is active as soon as the app is installed, and its runs appear with the workspace’s other workflow runs.
- Installing a new version of the app updates the workflow in place.
- Users can’t edit an installed workflow. To customize one, they duplicate it: the copy is theirs to edit.