Simple If-Then-Else example
Here we see a short and simple example of how a conditional branch is defined in practice, demonstrating the use of the If-Then-Else Heater.
What we want to achieve
This example inputs the following short CSV text file on the READ side:
The first field is the Product number, the second is the product Description, the third is the unit Price and the last field indicates the quantity remaining as Inventory. The first three fields are copied to the WRITE Adapter verbatim.
In this example we are only concerned with the Inventory field. If the Inventory is less than or equal to five, we want to write a notice into the field that the product should shortly be reordered.
The conditions are defined for the If Then Else Heater by using a double click on the Heater icon to open the properties window. In our case, we need only define one condition here. If the Inventory field contains a number greater than five (>5) then the field should be copied verbatim to the WRITE Adapter. However, if this is not the case and the value is less than or equal to five then the text "Inventory <= 5, product must be reordered" should be written to the Inventory field. Note: Since a numeric comparison of the incoming STRING data should be performed, the Change Data Type (INT) option is checked.
Here we have to use a little trick. Since the Inventory field is already connected to the If-Then-Else Heater as the first parameter, the value to be tested, we also need to insert a Clone Heater to replicate the Inventory value as the second If-Then-Else Heater input parameter, which is used to pass this value on when the condition is true.