Saltar para o conteúdo

Automation

Business rules

Business rules run every time a record is saved. Use them to fill in fields, check data, block changes, and update other records automatically.

Esta página ainda não foi traduzida. Está a ler o original.

A business rule reacts when a record in a table is created, updated, deleted, or restored. Rules keep your data correct on every save, no matter where the save comes from: a form, a kanban drag, the API, or a workflow step.

Rules run inside the save itself, as part of the same database transaction. If a rule refuses the save, nothing is stored. If a rule writes to another table and that write fails, the original save can be undone too.

The four rule types#

TypeWhat it doesWhen it runs
ComputationFills a field automaticallyBefore the record is stored, first
ValidationChecks the data and reports what is wrongBefore the record is stored, second
GuardBlocks a change outrightBefore the record is stored, third
Side effectWrites to other tables, or starts a workflowAfter the record is stored, in the same transaction

Every computation finishes before any validation starts, and every validation finishes before any guard starts. So validations and guards always see the values computations filled in. Within one type, rules run by their Order: lower runs first.

Create a rule#

  1. Open any view on the table, click Settings, and choose Business Rules.
  2. Click New rule.
  3. Enter a Name, such as "Approved orders cannot be edited", and optionally a Description.
  4. Pick a Rule type.
  5. Under Runs on, choose the operations: Create, Update, Delete, and Restore.
  6. Optionally pick fields under Only when these fields change. An update that doesn't touch those fields skips the rule. Leave it empty to react to any change.
  7. Under When, add conditions. Leave it empty and the rule runs on every matching save.
  8. Under Then, set what the rule does. This part depends on the rule type.
  9. Set the Order if several rules of the same type depend on each other.
  10. Make sure Rule is active is on, then click Create rule.
Dica: Click AI assistant in the rule editor and describe the rule in your own words, for example "orders over 10,000 need a manager in the approver field". The assistant drafts the rule. Click Load into form, check it, and save.

Restore is separate from Create on purpose. Bringing back an archived record can follow different logic than adding a new one.

Conditions#

A condition decides whether the rule applies to this save. You can combine these kinds:

ConditionUse it to
Field comparisonCompare a field with a value, another field, or the current user.
Field changedReact only when a field's value actually changes, optionally from a specific value or to a specific value.
Status changed toReact when a status field reaches a particular state.
All of…Group conditions that all have to hold.
Any of…Group conditions where one is enough.
Not…Invert whatever is inside.
Rows exist in…Check that another table has a matching record.
No rows exist in…Check that another table has no matching record.

Comparisons use operators such as is, is not, is more than, is less than, is at least, is at most, contains, starts with, is one of, is empty, and is not empty.

Values in conditions and actions#

SourceWhat it gives you
ValueA fixed value you type.
FieldA field on the record, either After the save (the new value) or Before it (the old value).
ContextA fact about the save: the Signed-in user, The user's groups, whether the User owns the organization, The user's permissions, Right now, the Current table, or the Current row.
RowThe whole record, before or after the save. Useful when you start a workflow.

Computations can also use a total from another table or a formula. See Computation.

Manage rules#

Each rule in the list shows a one-line summary of what it does, on which operations, and when. From a rule's menu you can:

  • Enable or Disable it without deleting it.
  • Edit it.
  • Duplicate it. The copy starts disabled so you can adjust it before it runs.
  • Open its Execution history.
  • Delete it. It stops running immediately. Records it already wrote stay as they are.

The Execution log tab shows every time rules ran on this table, with the outcome (Passed, Refused, Failed, or Skipped), the operation, how long it took, and a step-by-step trace.

What rules don't do#

Rules don't send email, wait, create PDFs, or call other systems. Those belong in a workflow. A side effect can start a workflow, and the workflow only starts after the save has been committed. It never runs for a save that was rolled back.

Some bulk operations skip business rules for speed, for example the Bulk Upsert DataView step in a workflow. Don't rely on a validation to protect records that arrive that way. Add the checks to the workflow before the write instead.

Nota: Business rules aren't available on time series tables. Business rules are included on selected plans. If Business Rules is greyed out in the view settings, your plan doesn't include it.

Plan your rules#

Write each rule as one sentence: on this table, on these operations, if this condition, then this effect. Name the type. Decide what the person sees when a guard or validation refuses the save, and write that message in their words. If one rule depends on another, give them an order, remembering that computations always run before validations, and validations before guards.

Ficou bloqueado ou encontrou algo em falta? Pergunte à comunidade.

Perguntar à comunidade

Ver como MarkdownSugerir uma melhoria