Workflows
A workflow reacts to a trigger by applying a short list of actions to one record: add or remove system tags, update system metadata, or write an attribute value. Workflows are versioned YAML, like blueprints, and every change they make goes through normal validation and appears in the audit log.
Workflows have no scripts, loops, queries, or network calls. They change the record that triggered them and, with one bounded action, the records that link to it through a named relationship. For anything bigger, write an extension.
A first workflow
Section titled “A first workflow”Tag a product for review whenever its title changes:
format_version: 1code: review-title-changename: Review title changes
triggers: - event_type: attribute_value.changed.v1 attributes: [title]
actions: - type: system_tags_add tags: [needs-review]Create, publish, and enable it under Manage → Workflows, or with the CLI:
acli workflow validate --file review-title-change.yamlacli workflow create --file review-title-change.yamlacli workflow publish <workflow-id> 1acli workflow enable <workflow-id> 1Enabling records the current point in the event stream. Only events after that point start runs; the workflow does not process history.
Definition
Section titled “Definition”| Key | Description |
|---|---|
format_version |
1 for event triggers only. 2 adds manual and schedule triggers. |
code |
Unique code. |
name |
Display name. |
triggers |
One or more triggers. |
actions |
One or more actions, applied in order. |
Event triggers
Section titled “Event triggers”An event trigger names one record event and optionally narrows it:
triggers: - event_type: record.updated.v1 envelope: {source_kind: api} facts: "facts.0.attribute_code": price "facts.0.context_code": PLevent_type is one of record.created.v1, record.updated.v1, record.migrated.v1, attribute_value.changed.v1, attribute_value.restored.v1, or relationship.changed.v1.
envelope matches event properties exactly: event_type, aggregate_kind, source_kind, source_name, or metadata.<key>.
facts matches the facts carried by the event. Each fact describes one changed attribute. Its fields are attribute_id, attribute_code, context_id, context_code, relationship_target_record_id, change_kind, before_value, and after_value. Address them as facts.<index>.<field>, where index 0 is the first fact.
The actions of an event-triggered workflow apply to the record the event is about.
React only to specific blueprints
Section titled “React only to specific blueprints”A workflow belongs to the whole workspace. blueprints lists 1 to 100 blueprint codes, and the trigger then starts a run only for records of those blueprints:
triggers: - event_type: record.updated.v1 blueprints: [product, service]- Every code must name a blueprint in the workspace when the workflow is saved, so a typo is rejected with
422 invalid_workflow_definitioninstead of silently stopping the workflow. - A record matches by its blueprint, whatever revision of it the record is on.
- When every trigger lists its blueprints, each
attribute_writeon the trigger record must name an attribute one of those blueprints declares in its latest published revision, or a reusable attribute. The editor flags a misspelt code as you type, and saving rejects it, so it never reaches a run. Writes inreferencing_records_updateare not checked this way, because referencing records can be of any blueprint. blueprintscombines withattributes,envelope, andfacts: all of them must match. Without it, the trigger matches records of every blueprint.- Manual and schedule triggers already name their record, so they don’t take
blueprints.
React only to specific attributes
Section titled “React only to specific attributes”attributes lists 1 to 100 attribute codes. The trigger then starts a run only when at least one of those attributes changed in the event, wherever it appears among the event’s facts:
triggers: - event_type: attribute_value.changed.v1 attributes: [body, revision_notes, license]
- event_type: relationship.changed.v1 attributes: [license]- A change is a fact in the event. Saving a value that is identical to the current one records no fact, so it does not start a run.
- A single save can produce
attribute_value.changed.v1,relationship.changed.v1, orrecord.updated.v1, depending on what it contains. List every event type the attributes can change through, as above. record.created.v1counts every value the new record starts with, including defaults, as changed.- Relationship attributes: adding or removing a target is a change to the relationship attribute. Each added or removed target is its own fact, with
change_kindrelationship_addorrelationship_remove. Changes to the linked record itself are events on that record, not on this one. - File attributes: uploading, linking, reordering, or removing files records
attribute_value.changed.v1with a fact for the attribute, so list that event type to react to file changes. attributescan’t be used withrecord.migrated.v1, which carries no facts. It combines withenvelopeandfacts: all of them must match.
React only to added or removed relationship targets
Section titled “React only to added or removed relationship targets”change_kinds lists the kinds of change the trigger reacts to. The trigger then starts a run only when the event has a fact of one of those kinds. With attributes, the same fact must also be for one of those attributes:
triggers: # A license was linked to the record - event_type: relationship.changed.v1 attributes: [license] change_kinds: [relationship_add]
# A license was unlinked from the record - event_type: relationship.changed.v1 attributes: [license] change_kinds: [relationship_remove]- The kinds are
set,replace,remove,restore,relationship_add, andrelationship_remove. See which changes produce facts. - A save that changes relationships together with other values records
record.updated.v1, notrelationship.changed.v1. Add a second trigger withevent_type: record.updated.v1and the same filters to catch those saves too. change_kindscan’t be used withrecord.migrated.v1. It combines with the other filters: all of them must match.
React only to added or removed tags
Section titled “React only to added or removed tags”tags_added and tags_removed each list 1 to 100 system tags. The trigger then starts a run only when the save added, or removed, at least one of them:
triggers: - event_type: record.updated.v1 tags_added: [approved]
- event_type: record.updated.v1 tags_removed: [approved]- Tags count only when they actually change. Saving a record with the tags it already has starts no run.
tags_addedworks withrecord.created.v1, where every tag the new record starts with counts as added, andrecord.updated.v1.tags_removedworks withrecord.updated.v1only.- Tag changes made by a workflow don’t start workflows, like any other change made by a workflow.
- Both combine with the other filters: all of them must match. To react to either change, use two triggers as above.
Manual and schedule triggers
Section titled “Manual and schedule triggers”With format_version: 2, a workflow can also be started by hand or on a schedule.
format_version: 2code: nightly-flagname: Nightly flag
triggers: - type: manual
- type: schedule cron: '0 0 2 * * *' timezone: UTC target_record_id: '00000000-0000-0000-0000-000000000001'
actions: - type: system_metadata_merge values: {last_nightly_check: done}- Manual: start a run against one record from the workflow page, or with
acli workflow run-now <workflow-id> --record-id <uuid> --idempotency-key <key>. It always uses the enabled revision. - Schedule: a six-field cron in UTC.
timezonemust be"UTC", which avoids repeated or skipped runs at daylight-saving changes.target_record_idis the record the actions apply to. If the server was down when a run was due, occurrences more than five minutes late are skipped and recorded. An occurrence is also skipped while a previous run is still pending.
Manual and scheduled runs have no event, so their actions must use fixed values.
Actions
Section titled “Actions”type |
Keys | Effect |
|---|---|---|
system_tags_add |
tags (1 to 100, each up to 128 bytes) |
Adds system tags. |
system_tags_remove |
tags |
Removes system tags. |
system_metadata_merge |
values (mapping of scalar values) |
Sets keys in system metadata. Keys may be dotted paths. |
system_metadata_delete |
keys |
Removes keys from system metadata. |
attribute_write |
attribute_code and exactly one of fixed or event_field |
Writes a scalar attribute value. fixed is a literal; event_field copies a value from the event, such as facts.0.after_value. |
referencing_records_update |
relationship_attribute, optional max_targets, and nested actions |
Applies the nested actions to every record that links to the trigger record. See below. |
attribute_write obeys the blueprint: type checks, schemas, and status transitions all apply.
Update records that reference the trigger record
Section titled “Update records that reference the trigger record”When a license, specification, or composition changes, the records that depend on it often need to go back to review. referencing_records_update finds every live record whose relationship_attribute currently links to the trigger record, in any context, and applies its nested actions to each of them:
format_version: 2code: license-changedname: Send licensed products back to review
triggers: - event_type: attribute_value.changed.v1 attributes: [terms]
actions: - type: referencing_records_update relationship_attribute: license max_targets: 200 actions: - type: attribute_write attribute_code: status fixed: in_review - type: system_tags_add tags: [needs-review]relationship_attributeis the code of the relationship attribute on the referencing records, not on the trigger record.- An action has 1 to 20 nested actions. They can set statuses and other attributes with fixed values, and add or remove system tags and metadata. They can’t use
event_field, and they can’t contain anotherreferencing_records_update. max_targetsdefaults to 100 and can be at most 500. If more records link to the trigger record, the action fails before changing any further record. Raise the limit or narrow the relationship.- Each record is updated in its own save, with the same checks as any other edit: schemas, checks, unique keys, enforcing rules, and status transitions, including their conditions, locks, and permission or role requirements. Transition requirements are checked against the person whose change started the workflow. A record that fails any of these, such as one whose status is locked or doesn’t allow the transition, fails on its own; the other records are still updated.
- If any record fails, the run is retried. A retry only revisits records that failed or weren’t reached; records already updated are never changed twice. A record that no longer exists or no longer links to the trigger record by then is skipped.
- See the outcome for each record, including its latest error, with
acli workflow run-targets <run-id>orGET /workflow-runs/{id}/targets. The run list shows the run’s overall error once it becomes a dead letter. - The records’ own changes don’t start workflows, like any other change made by a workflow.
How runs behave
Section titled “How runs behave”- Each run uses the revision that was enabled when it started, even if a newer one is enabled later.
- Delivery is at least once. Every action is recorded with its run so a retry never applies it twice. A
referencing_records_updateaction also records each record it updates. - A failed run is retried with increasing delays and becomes a dead letter after five attempts. Replay it from the workflow’s run list or with
acli workflow run-replay <run-id>. - Disabling a workflow cancels its queued and running runs.
- Changes made by a workflow do not trigger workflows again by default, and chains are capped at a depth of eight.
Not available yet
Section titled “Not available yet”extension_eventtriggers are accepted informat_version: 2definitions but no extension event is delivered to workflows yet.- Workflows cannot call webhooks, send email, or read secrets.
Permissions
Section titled “Permissions”workflows.read lets someone see workflows and run history. workflows.manage lets them create, publish, enable, disable, run, and replay. Both are granted to the owner and admin roles by default.