Code examples to replace expressions in Special Case rules
- Last UpdatedOct 15, 2026
- 2 minute read
In some cases, you can construct the special case rule with expressions which are expected to be replaced when the rule is run. The following example demonstrates this concept using a piping rule. For more information, see Code examples for Special Case rules.
The rules in the PDAI ruleset are designed to be run on a pipe branch. These rules must consider the pipe bore, but at the BRANCH level, you must specify the HBOR or TBOR (bore at head or tail of the branch).
It is unknown if the HBOR or TBOR is required when the rule is constructed, so a logical expression is constructed in the RLOGIC element. For example:
( ATTRIB BORE LT 100mm )
At runtime, the application determines the tail bore (TBOR) is required. You can modify the expression. For example:
( ATTRIB TBOR LT 100mm )
To achieve this, construct two arrays (to act as key-value pairs) and provide these to EvaluateRule:
if (!rule.badref().not() and !!ce.type.eq('BRAN')) then
!keys = object ARRAY()
!values = object ARRAY()
!keys[1] = 'BORE'
!values[1] = 'TBOR'
!result = !rulesEngine.evaluateRule(!!ce.name, !rule.name, !keys, !values)
endif
Now, if an expression appears containing the string ‘BORE’, it is replaced with the string ‘TBOR’, so the expressions can evaluate properly from a BRANCH. This concept can help in many scenarios:
-- Replace the word 'GENSEC' with an actual element name if
-- the gensec is not really related to the evaluating element
!keys[2] = 'GENSEC'
!values[2] = '/gensecName'
-- Replace a dummy real property with a calculated value
!keys[3] = 'ATTRIB RPRO A'
!values[3] = '15mm'
It is possible to control which keys are available when constructing rules using valid value lists in the Rule Manager window. For more information, see Rule Manager Programmable Macro Language customization.