Automation
Computation rules
A computation rule fills a field automatically when a record is saved. Learn how to set defaults, copy values, total other tables, and use formulas.
Esta página ainda não foi traduzida. Está a ler o original.
A computation fills a field on the record being saved. It runs first, before validations and guards, so those rules see the value it filled in. The value is stored with the record, which makes it searchable, sortable, and usable in filters like any other field.
Use a computation for values that should be set the moment a record is saved: a default status, the person who approved, an order total, a due date thirty days out.
Create a computation#
- Open any view on the table, click Settings, choose Business Rules, and click New rule.
- Enter a Name and set the Rule type to Computation.
- Under Runs on, choose Create, Update, or both.
- Optionally add conditions under When, or pick fields under Only when these fields change.
- Under Field to fill, pick the field the rule writes.
- Under Where the value comes from, choose a source and fill in its settings.
- Click Create rule.
Where the value comes from#
| Source | Use it for |
|---|---|
| A fixed value | Defaults, such as setting Status to "New" on create. |
| Another field on this row | Copying a value, such as keeping the billing address in the delivery address when it's empty. |
| Something about the user or the moment | Stamping who did something and when, such as "Approved by" and "Approved at". |
| A total from another table | Sum, Count, Average, Smallest, or Largest of a field across matching records in another table, such as the sum of an order's line amounts. Pick the From table and the Field, and filter to the related records. |
| A formula | Arithmetic and text built from fields on this record. |
Formulas#
In a formula, write field names in curly braces, such as {quantity} * {unit_price}, and the current time as {context.now}. Pick a Result type: Text, Number, Yes / no, or Date.
Examples#
| Computation | Runs on | Field to fill | Source |
|---|---|---|---|
| Default status | Create | Status | A fixed value: New |
| Line total | Create, Update | Line total | A formula: {quantity} * {unit_price} |
| Approval stamp | Update, when Status changed to Approved | Approved by | Something about the user: Signed-in user |
| Order total | Create, Update | Total | A total from another table: Sum of Amount in Order lines for this order |
Computation or a calculated column#
A Formula column updates whenever the columns it uses change, and a Rollup column always reflects the linked records as they are now. Use one of those when the value should simply follow the data.
Use a computation when the value depends on who is saving or when, comes from a table that isn't linked by a relation, or should be set at one moment and then stay fixed, such as the price at the time of order.
Discussões sobre esta página
Ficou bloqueado ou encontrou algo em falta? Pergunte à comunidade.