Evaluate() Returns False When Else-If Condition Evaluates True #4
-
|
We are encountering what appears to be an issue with rule evaluation involving else if branches and could use some direction. Versions CodeEffects.Rule.Common 5.0.8.2 IssueBased on the CodeEffects documentation, the Evaluate() method should return true when any rule branch evaluates to true. If the initial if condition evaluates to false, subsequent else if branches should be evaluated, and the rule should return true if one of those branches matches. However, we are observing behavior where an else if condition evaluates to true, but the overall rule evaluation returns false. Reproducible ExampleThe following simplified rule demonstrates the issue: If Age = 18, the rule evaluates to true as expected. XMLCan you confirm whether this behavior is expected, whether there are any additional evaluation settings required for nested else if branches, or whether this may be a defect in our rule XML? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Hello, The engine follows the standard .NET evaluation behavior for if / else if / else blocks and returns true only when the initial if condition evaluates to true. Any else if clauses are treated as nested subclauses. Therefore, the runtime returns false for the overall evaluation even when setters or rule actions within an else if or else clause are invoked. In other words, the initial if condition determines the rule’s return value; execution of any subsequent clause does not change it. The engine passes the compiled rule to the runtime, which effectively interprets it as follows: if (condition1)
{
action1();
return true;
}
else
{
if (condition2)
{
action2();
}
else
{
action3();
}
return false;
}The editor cannot display the rule in this nested form because it must show action1, action2, and action3 at separate levels, with each action appearing after its corresponding THEN clause. This difference between the visual representation and the compiled evaluation logic caused the confusion. You have two possible options:
Please let us know if you need any further assistance. |
Beta Was this translation helpful? Give feedback.
Hello,
The engine follows the standard .NET evaluation behavior for if / else if / else blocks and returns true only when the initial if condition evaluates to true.
Any else if clauses are treated as nested subclauses. Therefore, the runtime returns false for the overall evaluation even when setters or rule actions within an else if or else clause are invoked. In other words, the initial if condition determines the rule’s return value; execution of any subsequent clause does not change it.
The engine passes the compiled rule to the runtime, which effectively interprets it as follows: