Why do conditions evaluate to false when they should evaluate to true?

RPE 1.2 has changed the way variables are passed between assignments and conditions.  Prior to RPE 1.2 all variables were transformed to strings when introduced in a script expression. With RPE 1.2 the variables are no longer transformed to strings and they keep the type and exact value they received in the last assignment.

This change helps building and processing complex structures in JavaScript but it can also affect the behavior of existing templates in certain scenarios.  Some conditions will evaluate to a different value than the expected one which in turn will result in parts of the report incorrectly missing/showing up.

The one scenario we identified that this change has a negative impact is when dealing with variables that are compared to the string literals “true”/”false” in expressions like variable == “true”. If the value of the variable comes from the document specification,  i.e. it was provided by the user when configuring the report or it’s the default value of the variable, then everything will work as before since the variable is still a string. But if the value comes from a prior computation, say variable = (1 < 2), then the value of the variable will be the boolean true not the string literal “true”. And this in turn means that conditions such as  variable == “true” will evaluate to false even though you would expect them to evaluate to true.

To ensure the conditions will work as before you need to update them such that they will be able to handle both scenario. One such solution is to change from variable==”true” , which only checks for string equality, to a form that handles also the boolean comparison: (variable == true) || ( variable == “true”)

If you know for certain that your variable will always be either boolean or string you can design the condition to only cover that scenario. However given that templates evolve over time I would recommend that you make your conditions able to handle both scenarios.

Author: Dragos Cojocari

Architect for Rational Publishing Engine

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s