Calculated fields

A calculated field is a field that receives a value based on a given formula. The given formula can be specified using the spring expression language, as well as various helper functions.

You turn another base type into a calculated field by supplying the formula attribute. The actual field value is still stored as the original base type.

Calculation is supported for the following field types:

Single value calculation

A single value type with a formula will be visualised as a read-only control.

Example number calculation, rendering read-only control
document-definition:
  name: store
  content:
    - id: item
      label: "name"
      type: "String"
    - id: amount-items
      label: "# items"
      type: number
    - id: buy-value
      type: number
    - id: sell-value
      type: number
    - id: profit-per-item
      type: number
      formula: "$(sell-value) - $(buy-value)" (1)
1 Supply the formula that represents the value of the field. In this case, the value is the difference between the sell-value and the buy-value

Functions

Various helper functions are defined to define formulas for fields. The following table lists all functions that are currently available.

Method Parameters Remarks

count

Collection of objects

Returns how many items are present in the given collection

countNonNull

Collection of objects

Returns how many items are present in the given collection that differ from null.

countNull

Collection of objects

Returns how many null values are present in the given collection.

min

Collection of numeric values

Returns the smallest value in the collection.

max

Collection of numeric values

Returns the largest value in the collection.

sum

Collection of numeric values

Returns the sum of the values in the collection

avg

Collection of numeric values

Returns the average of the values in the collection.

isNotEmpty

Collection or array of objects

Returns whether the collection or array contains at least one item.

isEmpty

Collection or array of objects

Returns whether the collection or array contains zero elements.

and

Collection of boolean values

Returns whether the provided values are all true

or

Collection of boolean values

Returns whether one of the provided values is true

concat

Collection of textual

Returns the concatenated result of the provided values

join

Separator and a collection of textual values

Returns a single text that joins the provided textual values wit the provided separator.

sum

an unlimited amount of numbers or fields representing a number.

Example: sum( 5,23,89, $(myField) )

Performs the sum operation on all the given values.