About EasyMorph Tutorials & Examples Web-help

Place stronger conditions first in the Rule action


#1

When adding multiple similar conditions in the Rule action it is important that stronger (harder to match) conditions come first, and weaker (easier to match) come after them because the order of conditions matters - conditions are checked one by one starting from the first (top) down. When a matching condition is found it’s result is calculated and the rest of conditions is ignored.

Putting a weaker condition (from two similar conditions) before a stronger one will make the stronger one never reached. For instance, in the following example the second condition will be never matched:

IF BRAND = NIKE AND SUB-BRAND = AIRMAX THEN XXXXX
Else
IF BRAND = NIKE AND SUB-BRAND = AIRMAX AND color = RED THEN YYYY

Basically, the example means the following:

Condition 1: Brand must be NIKE. Sub-brand must be AIRMAX. Color can be any.
Condition 2: Brand must be NIKE. Sub-brand must be AIRMAX. Color must be red.

Because red is just a particular case (subset) of any it means that any time when Condition 2 is matched (satisfied) Condition 1 is matched too. But because Condition 1 comes first it “intercepts” all matches and Condition 2 is never reached.

To make the example work Condition 1 should be modified as follows:

IF BRAND = NIKE AND SUB-BRAND = AIRMAX AND color != RED THEN XXXXX
Else
IF BRAND = NIKE AND SUB-BRAND = AIRMAX AND color = RED THEN YYYY

Which would effectively mean the following:

Condition 1: Brand must be NIKE. Sub-brand must be AIRMAX. Color can be any except red.
Condition 2: Brand must be NIKE. Sub-brand must be AIRMAX. Color must be red.

Alternatively, reverse the order of conditions:

IF BRAND = NIKE AND SUB-BRAND = AIRMAX AND color = RED THEN YYYY
Else
IF BRAND = NIKE AND SUB-BRAND = AIRMAX THEN XXXXX

Note: in the examples above a pseudo-syntax was used. The actual syntax of expression condition in the Rule action would be:

[BRAND] = "NIKE" AND [SUB-BRAND] = "AIRMAX" AND [color] != "RED"

Read more about expression syntax of EasyMorph here: Web-help or Tutorial: Expressions