API · v1 · stable
CODEMETA OSDeveloper Center
EN
Open console
Concept

State machine & transitions

Reading time · 9 minUpdated · 1 May 2026

Practically every Codemeta entity with a status field has a state machine — a list of allowed status values plus rules on which change is permitted from which status. This machine is enforced server-side: a direct PATCH /api/v1/<resource>/:id with an impermissible status change is rejected.

The mechanics are identical across all modules — tickets, contracts, assets, DMS documents, opportunities, tasks, callback requests and tenant-specific custom workflows all use the same engine.

Components of a state machine

Term Meaning
Status Discrete state (e.g. OPEN, IN_PROGRESS, RESOLVED)
Transition Allowed change from one status to another
Guard Condition that must be met before the transition (e.g. “assignee present”)
Hook Action executed on entry/exit (e.g. “notification”)
Dialog UI interaction that the server requests before the transition
Approval External approval that temporarily pauses the transition

System vs. custom workflows

Codemeta OS ships system workflows for core entities. Example ticket:

OPEN → IN_PROGRESS   (Guard: assigneeId must be set)
IN_PROGRESS → WAITING
IN_PROGRESS → RESOLVED
WAITING → IN_PROGRESS
RESOLVED → CLOSED
* → OPEN              (Reopen from any status)

Tenants can override these defaults and define their own status values + transitions — per schema and per tenant. The engine prefers the tenant-specific workflow if present, otherwise the system defaults.

Ways to trigger

Status can be changed in two ways:

  1. Via the transitions API — the clean way. The server evaluates guards, requests dialogs, creates an approval request if needed, and runs hooks.
  2. Via a regular PATCH on the status field. Here too, the engine checks whether the change is allowed in the workflow — guards/hooks also run. Use this only for trivial cases without dialog/approval.

An attempt to set a “non-connected” status pair results in 400 Bad Request or 422 Unprocessable Entity with an RFC 7807 problem body.

Guards — what can block the change

Guards are named conditions on the edge between two statuses. A selection of the built-in guard types:

Guard Meaning
requiredFields Certain fields must not be empty
fieldValue Field must have a value eq/ne/gt/…
requireRole Executor must have a specific role
timeInStatus Minimum dwell time in the current status (minutes)
requireComment At least one comment/INTERNAL_NOTE must be attached to the ticket
requireTimeEntry At least one time entry with a minimum duration
noOpenSubtasks No open sub-task
checklist_complete Linked checklist must be done
requireApproval External approver must approve
requireAudit Audit catalog must be completed successfully
confirmDialog Server requests a confirm dialog before execution
inputDialog Server requests a text input dialog
formDialog Server requests a dynamic form
signatureDialog Server requests an acknowledgement/signature
customExpression Freely definable expression

If a guard fails, the API responds with 422 and a failedGuards[] array — the UI renders an understandable error message from it.

Hooks — what happens on the change

Hooks are actions that fire onEnter (entering the new status) or onExit (leaving the old status):

Hook Effect
setTimestamp Set timestamp field (e.g. resolvedAt)
clearTimestamp Clear timestamp field
setField / clearField Set/clear any field
copyField Source field → target field
incrementField Increment numeric field
addComment Append system comment
sendNotification In-app notification to user/role/field recipient
sendEmail Transactional email from template or free-form body
webhook Outbound HTTP call (your own receivers)
assignToUser / assignToRole Set responsibility
escalatePriority Raise priority
tagEntity Tags add/remove/set
createChecklist Create and link a checklist from a template
createFollowUpTask Create follow-up task
triggerWorkflow Trigger another workflow
createAudit Create audit assessment draft

Async hooks (sendEmail, sendNotification, webhook) run before the status write — if they fail, the transition fails.

Dialog gates — 428 Precondition Required

Some guards (confirmDialog, inputDialog, formDialog, signatureDialog) are interactive. A first call of the transition without a dialog response returns 428, with dialogConfig in the body. The client renders the dialog, collects the response and calls the transition again — this time with dialogResponse in the body.

HTTP/1.1 428 Precondition Required
{
  "type": "dialog_required",
  "title": "Dialog Required",
  "dialogConfig": {
    "type": "input",
    "title": "Closing reason",
    "inputLabel": "Reason",
    "inputRequired": true,
    "targetField": "closeReason"
  }
}

The dialog targetField is written to the entity automatically — the client does not have to send it again in fields.

Approval gates — 202 Accepted

The requireApproval guard opens an approval workflow: the platform creates an approval_requests record, sends an email with an approve/reject link if needed, and returns 202. The status does not change immediately — it changes only when the approver approves (or, on rejection, to the rejectionTargetStatus).

HTTP/1.1 202 Accepted
{
  "type": "approval_required",
  "approvalRequestId": "0192f2c0-…",
  "approverType": "role",
  "approverValue": "manager"
}

Audit trail of status changes

Every transition appends an entry to the audit history with from → to, the executing user, timestamp and reason (if captured from a dialog). The transition_history entry persists even if the status is later reverted.

SSE — follow status changes live

Anyone with a detail view open receives status changes via server-sent events (/api/v1/<resource>/<id>/stream). The event has type: 'entity-updated' and payload.action: 'transitioned' with from and to.

Search