Skip to content

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.

Tag a product for review whenever its title changes:

format_version: 1
code: review-title-change
name: 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:

Terminal window
acli workflow validate --file review-title-change.yaml
acli workflow create --file review-title-change.yaml
acli workflow publish <workflow-id> 1
acli workflow enable <workflow-id> 1

Enabling records the current point in the event stream. Only events after that point start runs; the workflow does not process history.

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.

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": PL

event_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.

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_definition instead 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_write on 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 in referencing_records_update are not checked this way, because referencing records can be of any blueprint.
  • blueprints combines with attributes, envelope, and facts: 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.

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, or record.updated.v1, depending on what it contains. List every event type the attributes can change through, as above.
  • record.created.v1 counts 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_kind relationship_add or relationship_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.v1 with a fact for the attribute, so list that event type to react to file changes.
  • attributes can’t be used with record.migrated.v1, which carries no facts. It combines with envelope and facts: 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, and relationship_remove. See which changes produce facts.
  • A save that changes relationships together with other values records record.updated.v1, not relationship.changed.v1. Add a second trigger with event_type: record.updated.v1 and the same filters to catch those saves too.
  • change_kinds can’t be used with record.migrated.v1. It combines with the other filters: all of them must match.

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_added works with record.created.v1, where every tag the new record starts with counts as added, and record.updated.v1. tags_removed works with record.updated.v1 only.
  • 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.

With format_version: 2, a workflow can also be started by hand or on a schedule.

format_version: 2
code: nightly-flag
name: 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. timezone must be "UTC", which avoids repeated or skipped runs at daylight-saving changes. target_record_id is 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.

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: 2
code: license-changed
name: 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_attribute is 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 another referencing_records_update.
  • max_targets defaults 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> or GET /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.
  • 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_update action 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.
  • extension_event triggers are accepted in format_version: 2 definitions but no extension event is delivered to workflows yet.
  • Workflows cannot call webhooks, send email, or read secrets.

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.