IF, OR, AND Statement Rule Engine

Just for the excitement of having yet another option ;-)… if you really want to, you can do nested if statements within String Manipulation too. It’s hidden away, but it’s there:

e.g.

string(

$column1$.equals("Y")
?"Some result"
:$column2$.equals("Y") && $column3$.equals("N") 
   ?"A different result"
   :$column2$.equals("Y")
      ?"Yet another result"
      :"Bored now!"

)

The syntax is

condition
? result if true
: result if false

and as you can see, you can nest the conditions. It’s not the nicest syntax, but I do use it periodically when it reduces the complexity of using other nodes to achieve the same result.

As it is using java syntax for the expressions, && represents “AND”.
“OR” would be represented by || which is a pair of “pipe” symbols.
e.g.
:$column2$.equals("Y") || $column3$.equals("N")

You can use just a single & or | symbol too, but && and || would be marginally more performant as they cause it to stop evaluating as soon as sufficient conditions have been evaluated that the result of the whole expression will be logically known (google short-circuit evaluation) :wink: .

image
image


image

Fun with String Manipulation - Nested conditions.knwf (7.0 KB)

11 Likes