Naar inhoud springen

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.

Deze pagina is nog niet vertaald. Je leest het origineel.

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#

  1. Open any view on the table, click Settings, choose Business Rules, and click New rule.
  2. Enter a Name and set the Rule type to Computation.
  3. Under Runs on, choose Create, Update, or both.
  4. Optionally add conditions under When, or pick fields under Only when these fields change.
  5. Under Field to fill, pick the field the rule writes.
  6. Under Where the value comes from, choose a source and fill in its settings.
  7. Click Create rule.

Where the value comes from#

SourceUse it for
A fixed valueDefaults, such as setting Status to "New" on create.
Another field on this rowCopying a value, such as keeping the billing address in the delivery address when it's empty.
Something about the user or the momentStamping who did something and when, such as "Approved by" and "Approved at".
A total from another tableSum, 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 formulaArithmetic 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#

ComputationRuns onField to fillSource
Default statusCreateStatusA fixed value: New
Line totalCreate, UpdateLine totalA formula: {quantity} * {unit_price}
Approval stampUpdate, when Status changed to ApprovedApproved bySomething about the user: Signed-in user
Order totalCreate, UpdateTotalA total from another table: Sum of Amount in Order lines for this order
Opmerking: A computation only runs when the record itself is saved. If a total depends on records in another table, such as order lines, the total doesn't update when a line changes. Add a side effect on the lines table that updates the order, or show the total with a Rollup column instead.

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.

Loop je vast of mis je iets? Vraag het de community.

Vraag het de community

Bekijken als MarkdownVerbetering voorstellen