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. However, it will be displayed in all the widgets where you want to see it and it will be available in the various places where you can set conditions.

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
  • 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)
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: