If-Else

Last updated on May 30, 2023
Description: Add an If-Else block to branch out the data based on conditions. You can then add appropriate Transformation blocks for the True and False conditions. The If-Else Transformation differs from the other blocks as you can create two Transformations based on the condition outcome.
Available Filters: Event Filters:
- Event Type
- Event Field
Settings: None.
Transformation Considerations: - The If-Else block branches the code to apply the Transformation. You cannot currently merge the branches post-Transformation, and have to write the subsequent Transformations for each branch separately.
- To delete the If-Else block, you must first delete its branches.

delete branches to delete IF-Else block

Sample Transformation

Scenario: If the author is Galos, Mike, then add a new field status with value Discontinued. Else, rename the field, price to discounted price and change its value to 90% of the original value.

Filters:

  • Event Type = catalog.book
  • Event Field = author with value = Galos, Mike

    If-Else filters

Settings:

  • True condition: Add a Field
    • New Field Name = status
    • New Field Value = Discontinued
  • False condition:
    • Rename Field
      • Field Name = price
      • New Name = discounted_price
    • Change Field Values (filter on Field Name = discounted_price)
      • New Value = 0.9*$self (The $self keyword is used here to indicate the price field.)

    If-Else blocks

Results: When you test the Transformation, the data is changed based on the condition outcome as follows:

  • If True: The status field is added with value as Discontinued:

    If-True

  • If False: The price field is renamed to discounted_price and its value is changed from 5.95 to 5.355:

    If-False


Revision History

Refer to the following table for the list of key updates made to this page:

Date Release Description of Change
Jan-10-2023 NA Enhanced the content for clarity.
Nov-10-2022 NA Created as a new document.

Tell us what went wrong