Multi-line boolean expressions
The validation script of a validation rule may consist of multiple boolean expressions. To increase legibility, you can use specific constructs.
Using the constructs makes your rule a little more verbose, but more readable in most cases.
Constructions
Expression | Purpose |
---|---|
allOf | All the conditions have to be valid (= AND ). |
anyOf | One or more of the conditions have to be valid (= OR ). |
condition | Capture the result of a boolean to re-use in other constructs. |
Examples
The examples below give the same result but are formulated in a single line, multi-line or in a hybrid construct.
Single-line expression:
rule { ((isNotEmpty (name) && isEqual (name, 'doesnotequal2', message: 'shouldfail')\ || isEqual (name, 'doesnotequal')) && isNotEmpty (id) }
Multi-line expression:
rule { allOf { anyOf { allOf { condition { isNotEmpty (name) } condition { isEqual (name, 'doesnotequal2', message:\ 'shouldfail') } } condition { isEqual (name, 'doesnotequal') } } condition { isNotEmpty (id) } } }
Hybrid expression:
rule { allOf { anyOf { condition { isNotEmpty (name) && isEqual (name,\ 'doesnotequal2', message: 'shouldfail') } condition { isEqual (name, 'doesnotequal') } } condition { isNotEmpty (id) } } }