Calculated fields cookbook
Section titled “Calculated fields cookbook”This how-to is for builders who want fields that work out their own value. You will choose when a calculation runs and which records it touches, then copy ready recipes: line and order totals, due dates, a status label, a full name, the days between two dates, and a value copied from a linked record.
The steps to set up a calculated value are in Settings every field shares. The expression syntax and every built-in function are in Write expressions. This page does not repeat them.
You need:
- Developer access to Administration and to the module you are building.
- The entity open in the entity builder, and the normalized names of the fields your expression reads.
- A test record to try each recipe on.
How a calculated value behaves
Section titled “How a calculated value behaves”You tick Advanced under Default Value and write the expression in Type expression. What happens next depends on Lock Field:
| Lock Field off | Lock Field on | |
|---|---|---|
| What you get | A starting value. People can change it. | A value the system maintains. Nobody can type over it. |
| Execution Triggers | Not shown. The value is worked out when the form opens. | Shown. You choose when the value is worked out. |
| Execution Scope | New entries | New entries, Existing entries or All entries |
| Server on save | Keeps what the person entered | Works the value out again, as the trigger and scope allow, and replaces any value sent for the field |
The expression runs in two places: live on the form as the triggers fire, and again on the server when the record is saved. So a record created by a reaction, an import or an integration gets the same value as one created on a form.
Choose the trigger
Section titled “Choose the trigger”| Execution Triggers | Runs | Use it for |
|---|---|---|
| On page load | When the form opens for a new record | Starting values: today, the current user |
| On field change | When one of the Watched fields changes | Values that depend on a few fields — the usual choice |
| On entry change | Whenever any field of the record changes | Totals over a repeatable block, values that read many fields |
| On save | When the record is saved | Values that should be fixed at save time, such as a reference code |
Choose the scope
Section titled “Choose the scope”| Execution Scope | Works the value out |
|---|---|
| New entries | Only while the record is being created |
| Existing entries | Only when an existing record is edited |
| All entries | On create and on every edit |
Choose the trigger first: changing the trigger resets the scope to New entries. With On page load, New entries is the only scope offered. If you clear the scope, the form never works the value out and the server does not recalculate it on save.
For exactly when the server works the value out, see the Field configuration reference.
Recipes
Section titled “Recipes”In each recipe, replace the normalized names with your own.
Line total in a repeatable block
Section titled “Line total in a repeatable block”An Order has a repeatable block Lines (lines) with Quantity (qty) and
Unit price (unitPrice). Add a Number field Line total inside the block.
(value.lines[scope.index].qty ?? 0) * (value.lines[scope.index].unitPrice ?? 0)- Lock Field: on (on Line total, inside the block).
- Execution Triggers: On entry change.
- Execution Scope: All entries.
scope.index is the row being worked out, so each row gets its own total.
Order total: the sum of a block column
Section titled “Order total: the sum of a block column”A Number field Order total outside the block adds up every row:
Math.round((value.lines ?? []).reduce((sum, row) => sum + (row.qty ?? 0) * (row.unitPrice ?? 0), 0) * 100) / 100- Lock Field: on.
- Execution Triggers: On entry change — it fires when a row is added, removed or changed.
- Execution Scope: All entries.
The expression multiplies again instead of reading Line total, so it never
depends on which field was worked out first. Math.round(… * 100) / 100 rounds to
two decimals and keeps the result a number.
Due date a set number of days after another date
Section titled “Due date a set number of days after another date”A Date field Due date is 14 days after Start date (startDate):
value.startDate ? new Date(new Date(value.startDate).getTime() + 14 * 86400000) : null- Lock Field: on.
- Execution Triggers: On field change, with Watched fields Start date.
- Execution Scope: All entries.
86400000 is one day in milliseconds. A Date field stores the result as a date
(yyyy-MM-dd). While Start date is empty, Due date stays empty.
Due date for a new record: today plus N days
Section titled “Due date for a new record: today plus N days”Field expressions cannot read when a record was created, so for “created plus 7 days” start from the moment the form opens:
new Date(Date.now() + 7 * 86400000)- Lock Field: off — people can still change the date.
- The trigger is On page load and the scope New entries.
A status label from other fields
Section titled “A status label from other fields”A Text field Approval level follows Amount (amount):
value.amount >= 10000 ? 'Director' : value.amount >= 1000 ? 'Manager' : 'None'- Lock Field: on.
- Execution Triggers: On field change, with Watched fields Amount.
- Execution Scope: All entries.
Use the label in queries, tags and reactions — for example a reaction that notifies directors when the label is Director.
Full name
Section titled “Full name”A Text field Full name joins First name (firstName) and Last name
(lastName):
[value.firstName, value.lastName].filter(Boolean).join(' ')- Lock Field: on.
- Execution Triggers: On field change, with Watched fields First name and Last name.
- Execution Scope: All entries.
filter(Boolean) drops empty parts, so there is no stray space when one name is
missing.
Days between two dates, or an age
Section titled “Days between two dates, or an age”A Number field Duration (days) from Start date to End date:
value.startDate && value.endDate ? Math.round((new Date(value.endDate) - new Date(value.startDate)) / 86400000) : nullAn age in whole years, from Birth date (birthDate):
value.birthDate ? Math.floor((Date.now() - new Date(value.birthDate)) / (365.25 * 86400000)) : null- Lock Field: on.
- Execution Triggers: On field change, watching the date fields.
- Execution Scope: All entries.
An age is worked out when its trigger fires, not every day. It is correct on the day the record changes and then ages with it — see Pitfalls.
Copy a value from a linked record Since 1.8
Section titled “Copy a value from a linked record Since 1.8”A Text field Customer email copies Email (email) from the record chosen in
the reference field Customer (customer):
resolveValue('value.customer.:relation.value.email')- Lock Field: on.
- Execution Triggers: On field change, with Watched fields Customer.
- Execution Scope: All entries.
How to write the path: start with value. and the reference field, add
.:relation.value. and the field of the linked record. Repeat
.:relation.value. to follow a reference on the linked record. Write the path
in quotes. When Customer is cleared, Customer email is cleared too.
The copy is taken when the trigger fires. If the customer’s email changes later, records that already copied it keep the old one.
Start with the current user or today
Section titled “Start with the current user or today”A User field Requested by, and a Date field Request date:
scope.me()scope.today()- Lock Field: off for a starting value people can change; on, with On save and New entries, to always record who created it and when.
See also User fields and Date fields.
Pitfalls
Section titled “Pitfalls”| Problem | Cause | Fix |
|---|---|---|
| The value is never filled | Execution Scope is empty | Choose a scope. Pick the trigger first — changing it resets the scope. |
| The value is filled on new records but not updated on edit | The scope is New entries | Use All entries (or Existing entries). |
| The value changes on the form but people can still overwrite it | Lock Field is off | Turn on Lock Field; then choose the trigger. |
| On field change does nothing | A field the expression reads is not in Watched fields | Watch every field the expression reads, or use On entry change. |
A date shift such as scope.today('+7d') gives today | Forms ignore the shift | Add days with Date arithmetic, as in the due date recipe. |
| The field shows as invalid, or the value is lost on save | The result has the wrong type: a number for a Text field, or a string for a Number field | Return a string for Text (`${value.total}`) and a number for Number. toFixed() returns a string — round with Math.round(x * 100) / 100 instead. |
The result is NaN or the expression fails | An empty field in the arithmetic | Guard with ?? 0 and ?. — see Handle empty values. |
| Days overdue or an age is out of date | Values are worked out only when a trigger fires, not as time passes | Show it in a view with a filter (scope.today()) instead, or accept that it updates on the next edit. |
| A value built from a sequence number is empty on create | The sequence number is assigned after calculated values | See Sequence fields. |
When the server cannot work the value out — an error, or an empty or wrong result — a locked field keeps its previous value on an edit, and stays empty on a new record.
See also
Section titled “See also”- Write expressions — syntax, field values, built-in functions and the expression editor.
- Settings every field shares — the steps to set up a calculated value.
- Lock a field — conditional locks and how locked values are protected.
- Allow more than one value: Multiple and Repeatable — repeatable blocks.
Platform 1.10.0 · Backend 1.11.0-alpha.11 · Frontend 1.11.0-alpha.6 · Mobile 1.10.2 · Chart 1.11.8 · Gateway 2.6.11 · MCP 0.2.0 · Grafana DS 1.2.0Docs build 2026-11-27