Rule value
Value resolver – Abstract
Purpose: Evaluates the configured rule and returns the check result as a Boolean value (true/false).
The Rule value resolver evaluates the configured rule and returns the check result as a Boolean value (true/false).
In this way, a test result can be used in a value assignment or as a comparison value in a rule.
Configuration
Clicking the The offer of rule types and rule type categories in the context menu may differ depending on the installed/licensed modules and the input value type defined by the context. Starting from the initially created rule, further rule types can be added AND or OR linked to represent arbitrarily complex logics (for details see Rule editor). ►Note◄ If no rule is configured, then the return value is by definition true. |
|
Examples
Simple use case: Check result as a value assignment for a field
Each time a user account (see Users) is saved (Create/Update), it is checked whether the 'Account number' (accountNumber) field is filled in the user's address.
The result of this check determines the status for the 'Active' (active) Boolean field, so that an account with 'Account number' is automatically 'Active' and one without 'Account number' is or becomes automatically 'Inactive'.
Configuration:
A specially set up event handler that reacts to the Triggering events 'Update' and 'Create' (see Common) is configured as shown on the right: The Validating rule uses Check type to ensure that the input value is a user account (see Users) that should be created or updated. A Set value event action is used here as the Action on passed rule for automatic value assignment:
|
|
►NOTE◄ The value assignment of the return value from the Rule value resolver solves the given task much more efficiently than an If then else event action with two alternative instances of the Set value event action in the IF and THEN branches could.
More complex use case: Store test results in variables
An association criterion, which is used as a 'logic module', checks an address (see Addresses) at each step and stores the result of each step (as far as this step was executed) in a variable. These variables with the check results can then be evaluated by subsequent association criteria or or in an event handling that refers to the association criteria as a Sub criterion rule in the 'Validating rule' without having to repeat the actual check.
For a clear use case, the 'logic module' should only contain two AND linked checks:
The first check determines whether the 'Account number' (accNumber) field in the address to be checked is populated.
The second check looks up – whether an 'Account number' is specified – and whether an address book entry exists that refers to this 'Account number'.
Configuration: An association criteria XF_ACCOUNT_EXISTS is configured as described below.
►IMPORTANT◄ This association criteria uses the Check existence value resolver, which implies access to the Lobster Data Platform / Orchestration database. Such database accesses should be triggered as seldom as possible and only in a targeted manner in consideration of performance. For our association criteria, this can be achieved by selecting the Logical component option (see Association criteria of type 'Logical component'). This causes the association criteria to be evaluated only if it is addressed directly and not automatically each time the context is updated.
The association criteria for the two-step check of the address is configured as shown on the right:
|
|
The following combinatorics results for the course of the tests by this association criteria:
Input value: |
Input value: |
Check resultaccountSpecified |
Check resultfoundInAddressBook |
Association criteria |
|
n/a |
$null |
$null |
|
|
<empty> |
(Fehler) false |
$null |
|
<new> |
(Haken) true |
(Fehler) false |
||
<known> |
(Haken) true |
|
If this association criteria is included as a Sub criterion rule, e.g. in an If then else event action, the following four different scenarios can be distinguished on the basis of the two variables, if required.
Based on this, a check of the addresses for a list of user accounts is executed and the check result per entry is output.
Runtime example:
User |
Address |
Account number |
Address book entry |
Check condition |
Output |
Ima |
|
17252 |
|
Association criteria XF_ACCOUNT_EXISTS → Rule passed! |
|
Karola |
|
17253 |
|
└ELSE: Variable foundInAddressBook = false |
|
Maik-Viktor |
|
<empty> |
n/a |
└ELSE: Variable accountSpecified = false |
|
|
<empty> |
<empty> |
n/a |
└ELSE |
Configuration:
In the Resolver for entities of the loop (see For each loop), a Collect values resolver determines the addresses of the associated user accounts starting from a given list of Long values ('User IDs'). The following concatenation of value resolvers is processed for each entry:
Input object (type safe): To convert the Long values into Users.
Object property: Value resolver for accessing the address field in the user account.
Default value: Value resolver that enters the false static Boolean value into the list if no address is found.
►NOTE◄ A $null value would otherwise simply be omitted by the Collect values resolver.
The two Set value event actions are used to ensure that in each iteration of the loop, the accountSpecified and foundInAddressBook variables are reset to 'no value' before the XF_ACCOUNT_EXISTS association criteria is evaluated.
The If then else event action checks through the fourfold case distinction 'from left to right' until one of the rules applies. Then the actions are executed below. In the example, a Show alert (Popup) event action with a specific message is executed in each case.
The first condition checks the association criteria XF_ACCOUNT_EXISTS as a Sub criterion rule. The accountSpecified and foundInAddressBook variables are assigned via the Rule value value resolver depending on the history.
The Sub criterion rule applies exactly when both variables contain the value $true. This case can therefore be identified without direct checks for variables.
The second condition checks if the foundInAddressBook variable has the value false. This value is assigned exactly when there is an 'Account number' to look up that is not yet in any address book.
The third condition checks if the accountSpecified variable has the value false . This value is assigned exactly when an address is present and it does not specify an 'Account number'.
The fourth branch of case differentiation does not use any condition. It is only entered if none of the conditions for other branches apply. This is only the case if the Check type for the 'address' type in the Sub criterion rule fails because there is no address to check but the Boolean value false from the Default value resolver in the Resolver for entities (see above).
Special use case: Evaluate a rule in the context of a search
The Regelwer resolver can also be useful if the condition of a search (see Search API) should include the check result of a rule or an association criteria (as a Sub criterion rule).
The following example demonstrates this using a configuration for a row formatting Condition in a datagrid (see Row formatting in datagrids, Datagrid preferences overview).
The Row formatter 'HIGHLIGHT' should emphasize all users in the data grid of an overview for Users for which the Company of session is the 'Owner' (ownerId). However, this format should only take effect if the Is Is mobile concludes that Lobster Data Platform / Orchestration is running on a mobile device. Within the condition, first the conventional check per Field restriction is executed for the 'Owner' (ownerId) field, which should match the ID (id) of the Company of session. The AND conjunction is then followed by another Field restriction that evaluates the Is mobile rule. Only on the right side of a Field restriction can value resolvers be accessed whose return value is considered static (i.e. 'the same for all rows') in the context of the search. Using the Rule value resolver, a Boolean value can be generated depending on the result of the Is mobile rule for the current session, which can be compared with a static Boolean Wert (as Literal projection), for example, as shown in the image. |
|
►NOTE◄ It is not possible to pass the data of the 'row to be evaluated' to which the condition refers as input value to the Rule value resolver. If the right side does not define a projection, a value is resolved only once, namely before the search starts.