Skip to Content
Droot Developers

Approval Step Conditions

Approval steps that run only in some cases: conditions joined by AND and OR, in groups; approval checks.

An approval rule (a matrix, defined with POST /api/admin/approval-matrices) is a list of steps. A step can run only in some cases: its when says when. A step without a when runs for every document. This guide is the shape of when, how AND and OR are mixed in it, and what Setup › Approval Rules writes.

The shape

{ "key": "cfo", "order": 2, "rule": "any", "approvers": [{ "type": "user", "id": "<user id>" }],
  "when": { "all": [ /* items */ ], "any": [ /* items */ ] } }

Every item of all must hold. When any has items, at least one of them must hold as well. Either list may be left out (it reads as empty). A step with a when that holds no condition at all is refused.

An item is a condition or a group:

  • A condition is { "field", "operator", "value"? }. It reads a field of the document, or, with "subject": "submitter" or "creator", an attribute of the person who submitted or created it. The operators and their values are the same as in a conditional scope.
  • A group is { "all": [ /* items */ ], "any": [ /* items */ ] }: it holds by its own two lists, in the same way.

Mixing AND and OR

You want when
A and B { "all": [A, B] }
A or B { "any": [A, B] }
A and B, or C { "any": [ { "all": [A, B] }, C ] }
A and (B or C) { "all": [ A, { "any": [B, C] } ] }
(A and (B or C)) or D { "any": [ { "all": [A, { "any": [B, C] }] }, D ] }

A rule written before groups existed (all and any of plain conditions) means exactly what it did: every all condition, and one of the any conditions.

Limits

  • A group needs at least one condition. An empty group is refused.
  • Groups nest at most 3 deep, counting the when itself as the first level.
  • A step's when holds at most 50 conditions in all, groups included, and each list at most 50 items.
  • These checks run whenever a rule is defined: a refused body answers with a list of problems that name the step and the group (for example step "cfo" when group any[1]: needs at least one condition).

A conditional scope (which rule applies to a record) takes plain conditions only: groups are for steps.

Which rule applies (the scope)

Only one rule runs for a submission. The rule's scope decides which rules can apply:

"scope": { "type": "conditional",
  "all": [ { "field": "scopeEntityId", "operator": "eq", "value": "co1" },
           { "subject": "creator", "field": "roles", "operator": "contains", "value": "site-engineer" } ],
  "any": [ { "field": "amount", "operator": "gt", "value": 50000 }, { "field": "project", "operator": "eq", "value": "metro" } ] }

Every all condition must hold and, when any has conditions, at least one of them too: with none holding, the rule does not apply. { "type": "global" } applies to every record. Among the rules that apply, the kernel takes a record scope over a conditional one over a global one (whatever the priority), then the deepest company anchor (within), then the higher priority, then the key A to Z. When every step of the chosen rule is skipped the submission is refused and no other rule is tried; when no rule applies it is refused too (unless the flow offers approval without a rule). Route between rules with the scope, not with step conditions.

In Setup › Approval Rules, Applies To edits it: the Company (written first in all, so a company-limited admin's rule stays pinned), All Of These and And At Least One Of These, each condition about the document, who created it or who submits it. Parts it can't show (a company within a hierarchy, several companies) are kept as stored and an untouched scope is saved exactly as it was. "In Plain Words" reads it ("Applies when Creator's Role is Site Engineer and …").

  • GET /api/admin/approval-matrices/warnings?modelKey= — each rule's warnings by key: overlap_same_priority (another rule of the same kind can match at the same priority: the key decides), never_used / hides_global (two global rules), conditional_wins (a global rule's priority never lifts it over a conditional one), no_fallback (no global rule), and every_step_conditional. The check before save (/preview) returns the edit's own warnings. Warnings never refuse.
  • POST /api/admin/approval-matrices/dry-run { modelKey, recordId, submitterId?, matrix? } — which rule the record would use, reason (only, specificity, anchor, priority, key), every rule that applies, outcome (routes, no_rule, every_step_skipped) and the steps with their approvers. matrix (the unsaved rule) takes the stored rule's place; the submitter defaults to the record's creator. Writes nothing. Setup's Test With A Record calls it.

In Setup

Setup › Approval Rules shows a step's conditions as a chain after "Only when". Each join between two conditions is its own AND or OR, and a click flips it. + Condition adds a condition joined with AND, + Or Condition one joined with OR.

The chain is read with AND before OR: A and B or C is (A and B) or C. Once an OR is in the chain, each run of ANDs is drawn as one group so the meaning is plain, and the step's sentence brackets them the same way.

What Setup writes is the smallest shape: one run of ANDs is { "all": [...] }; several runs are { "any": [...] } of single conditions and { "all": [...] } groups. A rule stored as "all of these and one of those" opens as the equal runs (A and (B or C) as (A and B) or (A and C)) and is saved that way.

A condition about who created or submits the document ("subject": "creator" or "submitter") is a chip like any other: the condition popover's Created By and Submitted By pick the attribute (role, group, person, company, position, org unit, grade) and its values. Only a company within a hierarchy (within) is kept as stored outside the chain. A step whose conditions can't be shown as a chain without changing what they mean (such a condition inside a group, or a very large expression) is shown with a note and kept as stored; change it with Droot AI or the API.

Why the step applies

An approval keeps each step's when from the moment it started (instance.steps[].when in GET /api/approvals/:modelKey/records/:id), so the approver can be told why the step is theirs ("Amount is at least 10000") even after the rule is edited.

Approval checks

A rule can also list checks: what the approver sees checked before deciding. A condition check uses the same shape as when, but it fails when its conditions hold:

{ "checks": [
  { "key": "limit", "label": "Within the Limit", "kind": "condition", "severity": "block",
    "failWhen": { "all": [{ "field": "amount", "operator": "gt", "value": 50000 }], "any": [] },
    "message": "Amount {{amount}} is over the 50000 limit", "tag": "Over Limit", "passTag": "Within Limit" },
  { "key": "duplicate", "label": "Not a Duplicate", "kind": "duplicate", "severity": "warning" }
] }
  • kind: condition (with failWhen) or duplicate (fails when the model's duplicate rules find a similar record).
  • severity: warning shows the result; block also refuses Approve with approval_check_failed (409). Reject and set back stay open.
  • message is shown when the check fails; {{field}} reads the record's value as the approver may read it.
  • tag and passTag name the result in the Approvals page's Signal column.
  • At most 20 checks; keys are unique, lower-case. They are copied onto each approval when it starts.

The record's approval state (checks) evaluates every check as the reader. Each decision keeps the results its approver saw (steps[].decisions[].checks). In Setup › Approval Rules, Checks edits them with the same condition chain as a step.