Skip to main content

Auto fields

Auto fields are special fields that are automatically filled according to a formula. You can use them to calculate values automatically based on other fields. This is one of the most powerful features of Bobuild.

When a field is set to auto, it will be read-only thus not editable directly by users. Task create/update actions that assign to an auto field (or to the primary key) are ignored at runtime — App Health warns when a task still targets them. Auto fields are displayed in all the widgets where you want to see them and remain available wherever you set conditions.

If you only need a calculation while the user is filling a form (for example a line total from price × quantity), use a form Live formula instead — it runs in the browser as they type and does not require an auto field.

How to create an auto field​

Any field can be set to auto, so the first step is to create the field just like you would create any other field. After that, just go to the field settings and open the "Automatic Value" section:

Now click on the "Enable Automatic Value" and your first rule will be created:

Ta-dah! Now you're ready to configure your formula.

Formula​

There are several types of formulas you can use.

These formulas are available for any field:

  • Set to a given value: this is the simplest formula. Use it to set a fixed value for the field. It's mostly useful when defining multiple conditional rules for the same auto field (see below)
  • Set to a field value: this will copy the value from another field of the same type. The source field can belong to the same object or to a connected object

These formulas are available for textual fields:

  • Set to a text expression: this will evaluate the provided expression and set the field to the resulting string (see below)
  • Set to the concatenated values of a field: this will get all the values of a field of a connected object, and concatenate them into a single string using the specified separator. For instance, you can use this to get the names of all the items in an order. You can optionally Order by a field of the related object (ascending or descending) so the concatenated list is stable and readable.
  • Set to the {first, last} value of a field: this will get the first (or the last) value of a field from a group of connected records. For instance, you can use this to get the name of the first item in an order

These formulas are available for numeric fields:

  • Set to a numeric expression: this will evaluate the provided expression and set the field to the resulting number (see below)
  • Set to the count of records of type: this will count the connected records of the specified type and set the field to the resulting number. For instance, you can use this to count the number of items in an order
  • Set to the {sum, average, minimum value, maximum value} of a field: this will calculate the requested function on a group of connected records. For instance, you can use this to calculate the total price of an order

These formulas are available for date/time fields:

  • Set to a date expression: this will evaluate the provided expression and set the field to the resulting date/time (see below)

Combining multiple rules​

When an auto field has several conditional rules, choose how results combine under Set this field:

  • to the last rule that matches — classic behaviour: one winning rule
  • to the aggregated values of all the matching rules — merge contributions from every matching rule
  • to the aggregated unique values of all the matching rules — same, but duplicate values are dropped

Aggregate unique is useful for tag-like text built from several optional sources where the same label must not appear twice.

tip

All the formulas that work on connected records can actually be used also on non-connected records, specifying a custom filtering criteria.

For instance, suppose you have an object called Event and you want to count the number of events that are taking place in the same day: you can create an auto field called events_count and set the formula to "Set to the count of records of type Event where start_date is equal to {start_date}".

Numeric expressions​

Numeric fields support numeric expressions. These expressions can be used to perform simple calculations on the values of other fields and get the resulting total. Any other numeric field can be used in the expression, as well as any non-numeric field if transformed using a placeholder function.

Examples
ExpressionDescription
{amount} + {tax}Sum of two fields
({price1} + {price2}) / 2Average of two fields
({end_date:to_seconds}-{start_date:to_seconds})/86400Number of days between two date fields

Textual expressions​

Textual fields can be populated with textual expressions which allow a wide range of operations using placeholder functions.

Examples
ExpressionSample resultDescription
P{id}P42Concatenation of the letter "P" with the ID of the record
P{id:lpad(5, '0')}P00042Concatenation of the letter "P" with the ID of the record, with padding
{name} {lastname}John SmithFull name of a person
{name:upper} {lastname:upper}JOHN SMITHFull name of a person, but uppercase

Date/time expressions​

Date/time fields can be populated with expressions using placeholder functions.

Examples
ExpressionDescription
{start_date:sub_days(3)}Compute a date before the beginning of an event, useful to send a reminder or set a deadline
{birth_date:add_years(18)}Compute the date when a person becomes of legal age (to be used elsewhere in your app to perform an action based on an age check)

Conditional rules​

As you can see, the fule has a "When" section that lets you define a condition. If you don't set any condition, the formula will be always applied. If you set a condition, the formula will be applied only when the condition is met. Using the plus button on the right, you can add as many rules as you want. Note that rules will be evaluated in the order they are listed.

Example

Suppose you want to apply a discount to your customers based on their age. You can create an auto field called discount and set two conditional rules like this:

If no auto rule matches a record, the field will be populated with the value set as default value:

Performance and recalculation​

On large apps, automatic fields recalculate when source data changes. For heavy imports or batch jobs you can temporarily disable automatic fields under Settings → Advanced, then re-enable them and watch the Recalculation Log (progress, ETA, stop) until values are consistent again.