Mapping transformation use cases

Summary

Transformations in action: real-world use cases

Using transformations can unlock a multitude of possibilities. However, the great flexibility of this tool comes with significant complexity and makes it difficult to find the right way to accomplish some complicated tasks. In this article, we will explore some practical applications of transformations.

 

Extracting a table attribute cell

Scenario

We have a table attribute named nutrition_table with three columns: nutrition_facts which is a select field acting as line identifier, amount_per_serving which is a number, and percentage_daily_value which is also a number.

We have a product named Chocolate protein bar. For this product, the nutrition_table contains several lines. One of these line has calories as nutrition_facts, 200 as amount_per_serving, and 10 as percentage_daily_value.

We have an app catalog with a mapping target named numberOfCalories. The target type is number

Our goal is to map the cell amount_per_serving of the line that concerns the “calories” to the numberOfCalories target.

 

How to realize the extraction

First, we select the numberOfCalories target. We use the ADD SOURCE menu to select our nutrition_table attribute.

Next, we need to use two ARRAYELEMENT functions. 

  • The first is used to extract the desired line from the table attribute: 
    ARRAYELEMENT(nutrition_table, “calories”)
    The first parameter is the source code of the attribute. The second one is the line identifier, which corresponds to the value (calories) entered in the first column (nutrition_facts) of the table attribute (nutrition_table).
  • The second takes the result of the first and extracts the specific cell from the selected line: ARRAYELEMENT(result_of_previous_function, “amount_per_serving”)

The complete formula would be: 

ARRAYELEMENT(
    ARRAYELEMENT(nutrition_table, "calories"), 
    "amount_per_serving"
)