Required boolean values of conditions
The expression mechanism sometimes requires that the calculated value is required. This happens in all places where a decision is made:
- Condition of classification of records in a block
- A condition for performing a mapping operation
- Validation rule
- etc.
In each of these places, the system must make an obvious YES or NO decision and the answer "not known" is unacceptable.
What if we have written some complex expression using non-required fields and we need a required value?
Three approaches can be considered - error, from above, from below.
Let's take an example of such an expression:
Amount * Rate > ..\config\Threshold
Here, in the case of non-requiredness of any field, the condition will be a non-required logical value.
Three possibilities for proceeding:
- Error - in this approach, in the mapping, we force our fields to be required even before the calculation (and make sure that the operations occur before the calculation operation, moving them there if necessary). As a result, our expression, which is then already based on the required fields, will also produce a fully required result of the calculation. If there is a missing input value, the entire record will be rejected as an error.
We select our fields and in the context menu we enable the "Mandatory" option for them.
- From the top - in this approach, regardless of the reason for the appearance of empty values and how they are propagated to the top, the entire result will be a required logical value "true".
Example of solution:
(Amount * Rate > ..\config\Threshold) ?? true
3. From the bottom - here you need to think about the possible substitute value for each non-required field entering the calculation and apply a workaround if necessary.
Example of solution:
Amount???0 * Rate???1 > ..\config\Threshold???1000000000
Example of a solution using the ?? operator and the brackets required in this case (a`la C# / Java):
(Amount ?? 0) * (Rate ?? 1) > (..\config\Threshold ?? 1000000000)
We encourage you to read the description of the arithmetic of null values and types of other special values of each type. See Special cases: no value vs. empty value