Skip to content
npm

Calculated values

Two Logic properties produce values instead of true/false.

Expression

Expression continuously calculates the element's value. Whenever a referenced field changes, the result is recomputed and written into the field.

text
{price} * {quantity}                            line total
{firstName} + " " + {lastName}                  full name
{isCompany} ? {companyCode} : {personalCode}    pick one of two codes
sumInArray({orderLines}, "total")               sum over table rows

Rules of thumb:

  • A field with an Expression is effectively computed, so combine it with Read only and users won't fight the recalculation.
  • Never reference the field itself; self-referencing expressions are skipped with a console warning.
  • On Number elements the result respects the element's formatting settings (fraction digits, locale).
  • If the expression errors or returns nothing, the value is cleared.
  • To land the result somewhere else instead of in this field, write it: {variable1} = sumInArray({orderLines}, "total"). See Writing values back.

Default value

Default value sets the initial value once, on load. The user can overwrite it.

Three forms:

FormExampleResult
Static textDraftliteral "Draft"
Token{__variables.route.id}resolved at load
Expression (prefix =)=today()evaluated at load

Common defaults:

text
=today()                        today's date
{__external.userName}           current user from the host app
{__variables.route.clientId}    id from the URL
"LT"                            fixed country pre-selection

Expression vs. Default value

ExpressionDefault value
When it runscontinuouslyonce at load
User can overrideno (recalculated)yes
Use fortotals, derived fieldssensible starting values

Worked example: invoice line

ElementTypeSetup
quantityNumberDefault value 1
unitPriceNumberfilled from a product data source
discountNumberDefault value 0
lineTotalNumber, read-onlyExpression: {quantity} * {unitPrice} * (1 - {discount} / 100)