Evaluables
Evaluables are a core concept in mos. and are used in conditions, dynamicParams and dynamicValues.
Definition
An evaluable in mos. is a binary tree that represents an expression. The tree was chosen as a representation because it avoids precedence and the need of parentheses. The order of operation inside a binary tree is always clear by its nature.
There are nodes in an evaluable, which require either zero, one oder two child nodes. The child nodes are always referenced as left
and right
. If there is only one child node, it will always be left
.
A simple boolean expression, written as a == b
would be the following, where the values for a
and b
are retrieved in left
and right
:
{
"mode": "equals",
"left": {
// a
},
"right": {
// b
}
}
As a binary tree, this would look like this:
Boolean Expressions
Boolean expressions are used for comparison and are nodes that return either true
or false
. Their node is called mode
and can be one of the following:
Mode | Description |
---|---|
exists | Checks whether the left sides exists. |
equal | Checks whether the two sides are equal. |
notEqual | Checks whether the two sides are not equal. |
and | And-connection of two conditions (both must return true for the whole condition to be true ). |
or | Or-connection of two conditions (at least one of the two must return true for the entire condition to be true ). |
not | Negates the result of the test (only left is evaluated, so right can be ignored). |
startsWith | Checks whether the left side starts with the right side. |
endsWith | Checks whether the left side ends with the right side. |
greaterOrEquals | Checks whether the left side is larger or equal to the right side. |
greaterThan | Checks whether the left side is larger than the right. |
lessOrEquals | Checks whether the left side is smaller or equal to the right side. |
lessThan | Checks whether the left side is smaller than the right side. |
matchesRegex | Checks whether the left side matches the regular expression on the right side. |
Boolean expressions are primarily used in conditions, but it is also possible to convert the true
and false
values to other values with the trueValue
and falseValue
fields, which are value expressions.
Examples
Goal: Check that the status code of a request is not 500 - internal server error.
{
"mode": "notEqual",
"left": {
"context": "parameter",
"field": "_statusCode"
},
"right": {
"value": "500"
}
}
Goal: Check whether the entered e-mail address in the form of the currently active view matches the regular expression of a valid e-mail address.
{
"mode": "matchesRegex",
"left": {
"context": "form",
"field": "mail"
},
"right": {
"value": "(^.+@.+\\..+$)"
}
}
Goal: Check whether the e-mail address is subscribed or another consent was granted.
{
"mode": "or",
"left": {
"mode": "equal",
"left": {
"value": true
},
"right": {
"context": "parameter",
"field": "subscriptions.marketingPermission.email.isSubscribed"
}
},
"right": {
"mode": "equal",
"left": {
"value": true
},
"right": {
"context": "parameter",
"field": "preferences.marketingPermission.letter.isConsentGranted"
}
}
}
Value Expressions
Value expressions are used to read and display information from various sources, like db_tables, forms, event parameters, user settings, variables, permissions and basic device and app information.
In the simplest case a value expression has a field value. The value can be set by known mechanisms like client templates.
Examples
Goal: Simple value, which is just a value.
{
"value": "Simple Value"
}
Goal: Value expression which uses the value behind the field myField
in a client template.
{
"value": "{{myField}}"
}
The context
field controls what is to be read dynamically. For most contexts, the value of field
must specify what exactly is to be read (e.g. the name of a user setting). Some contexts, like queries, may need more information. Below is a list of all possible context values.
context Value | Description | Possible field Values |
---|---|---|
parameter | Finds the specified field in the event parameters passed to the event and returns the value of the field. | |
userSetting | Searches for the specified field in the user settings and returns the value of the setting. | |
form | Searches for the specified field in the form data of the active view and returns the value. | |
namedForm | Searches for the specified field in the named form and returns the value. | form:field |
layerStatus | Searches for the specified layer in the active view and returns its active state as value. Alternatively: It is possible to search for a field in the layer. E. g., the index in a Gallery layer. Layer name and field are separated by a : . | childCount , index (Gallery),indexFromBehind (Gallery), state |
device | Retrieves information about the device. | category , darkModeEnabled , googlePlayServicesMissing , hasDisplayLock , isOnline , locationEnabled , model , networkType , os , systemBuildNumber , systemVersionNumber |
app | Retrieves information about the app. | buildNumber , identifier , name , updateAvailable , updateAvailableSince , mosVersion , versionNumber |
screen | Retrieves information about the screen. | dpi , height , orientation , width |
user | Retrieves information about the user. | uid , language |
audioPlayer | Checks if the active audio player is currently playing something. | playing , progress , time , duration , loaded |
date | Retrieves the current date as a time stamp. | updateInterval in seconds |
capability | Checks whether the device supports the specified capability. | camera , location , nfc , biometry |
permission | Checks if the user has granted the specified permission. | location , locationBackground , push , camera , audio , photoLibrary , calendar , contacts |
query | Retrieves a value by database query | table , query , queryParams , field |
variable | Retrieves a global variable | left (name of variable) |
Examples
Goal: Retrieve the value of the mail
form field of the form of the current view.
{
"context": "form",
"field": "mail"
}
Goal: Retrieve the value in the event parameter with the key subField
in the part behind the key myField
.
{
"context": "parameter",
"field": "myField.subField"
}
Goal: Retrieve the index of the currently visible element of the gallery with the name gallery
.
{
"context": "layerStatus",
"field": "gallery:index"
}
Transformation Expressions
Values can be transformed using transformation expressions. This ranges from basic arithmetic operations to date formatting or basic string operations.
transform Value | Description |
---|---|
add | Adds the values left + right . |
sub | Substracts the values left - right . |
mul | Multiplies the values left * right . |
div | Divides the values left / right . |
mod | Calculates the modulo left % right . |
parseDate | Parses the string value of left into a date using the format specified in right . |
formatDate | Converts the date value of left into a string using the format specified in right . |
replace | In left the string search will be replaced with right . |
replaceRegex | In left the regular expression search will be replaced with right . |
append | To left the string right will be appended. |
roundToDigits | The decimal left will be rounded to right decimal places. |
subString | The string left will be reduced to the rang in right in the form from:until . |
split | The string left will be split at the string right . useTail determines if the string behind right will be returned. |
fallback | If left is null or empty string right will be returned. |
translate | Translates the left string. |
Examples
Goal: Boolean expression that checks whether the current hour of the day is at least 13 in 24-hour format. Or, in other words, whether it is past 12:59.
{
"left": {
"left": {
"context": "date"
},
"right": {
"value": "HH"
},
"transform": "formatDate"
},
"right": {
"value": "13"
},
"mode": "greaterOrEquals"
}