Skip to main content

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:

Binary tree representing the boolean expression a == b Binary tree representing the boolean expression a == b

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:

ModeDescription
existsChecks whether the left sides exists.
equalChecks whether the two sides are equal.
notEqualChecks whether the two sides are not equal.
andAnd-connection of two conditions (both must return true for the whole condition to be true).
orOr-connection of two conditions (at least one of the two must return true for the entire condition to be true).
notNegates the result of the test (only left is evaluated, so right can be ignored).
startsWithChecks whether the left side starts with the right side.
endsWithChecks whether the left side ends with the right side.
greaterOrEqualsChecks whether the left side is larger or equal to the right side.
greaterThanChecks whether the left side is larger than the right.
lessOrEqualsChecks whether the left side is smaller or equal to the right side.
lessThanChecks whether the left side is smaller than the right side.
matchesRegexChecks 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 ValueDescriptionPossible field Values
parameterFinds the specified field in the event parameters passed to the event and returns the value of the field.
userSettingSearches for the specified field in the user settings and returns the value of the setting.
formSearches for the specified field in the form data of the active view and returns the value.
namedFormSearches for the specified field in the named form and returns the value.form:field
layerStatusSearches 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
deviceRetrieves information about the device.category, darkModeEnabled, googlePlayServicesMissing, hasDisplayLock, isOnline, locationEnabled, model, networkType, os, systemBuildNumber, systemVersionNumber
appRetrieves information about the app.buildNumber, identifier, name, updateAvailable, updateAvailableSince, mosVersion, versionNumber
screenRetrieves information about the screen.dpi, height, orientation, width
userRetrieves information about the user.uid, language
audioPlayerChecks if the active audio player is currently playing something.playing, progress, time, duration, loaded
dateRetrieves the current date as a time stamp.updateInterval in seconds
capabilityChecks whether the device supports the specified capability.camera, location, nfc, biometry
permissionChecks if the user has granted the specified permission.location, locationBackground, push, camera, audio, photoLibrary, calendar, contacts
queryRetrieves a value by database querytable, query, queryParams, field
variableRetrieves a global variableleft (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 ValueDescription
addAdds the values left + right.
subSubstracts the values left - right.
mulMultiplies the values left * right.
divDivides the values left / right.
modCalculates the modulo left % right.
parseDateParses the string value of left into a date using the format specified in right.
formatDateConverts the date value of left into a string using the format specified in right.
replaceIn left the string search will be replaced with right.
replaceRegexIn left the regular expression search will be replaced with right.
appendTo left the string right will be appended.
roundToDigitsThe decimal left will be rounded to right decimal places.
subStringThe string left will be reduced to the rang in right in the form from:until.
splitThe string left will be split at the string right. useTail determines if the string behind right will be returned.
fallbackIf left is null or empty string right will be returned.
translateTranslates 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"
}