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.
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 |
---|---|---|
|
Collection of objects |
Returns how many items are present in the given collection |
|
Collection of objects |
Returns how many items are present in the given collection that differ from null. |
|
Collection of objects |
Returns how many null values are present in the given collection. |
|
Collection of numeric values |
Returns the smallest value in the collection. |
|
Collection of numeric values |
Returns the largest value in the collection. |
|
Collection of numeric values |
Returns the sum of the values in the collection |
|
Collection of numeric values |
Returns the average of the values in the collection. |
|
Collection or array of objects |
Returns whether the collection or array contains at least one item. |
|
Collection or array of objects |
Returns whether the collection or array contains zero elements. |
|
Collection of boolean values |
Returns whether the provided values are all true |
|
Collection of boolean values |
Returns whether one of the provided values is true |
|
Collection of textual |
Returns the concatenated result of the provided values |
|
Separator and a collection of textual values |
Returns a single text that joins the provided textual values wit the provided separator. |
|
an unlimited amount of numbers or fields representing a number. Example: |
Performs the sum operation on all the given values. |