Problem Statement:
The client needs to design a mapping rule where the transformation logic should check if the node for student data ($Input/Root/item/orderItems/StudentData) does not exist. In such cases, the mapping should use an alternative field ($Input/Root/item/orderItems/sku).
This conditional decision is required so that the output is consistent with the availability or absence of student names.
Use Case:
Customer Requirement:
- The customer wants to print all associated nicknames.
- If there is student data available (i.e., when the student name is provided), it must be printed.
- Conversely, if the student name array is empty, the nickname field should be left blank.
Example Data:
Here,
- For SKU COBCON1TEE: the sample data includes three student names
- For SKU BBP01THE: there is no student data
Expected CSV Output:
- For SKU COBCON1TEE, there will be three rows – one for each student name.
- For SKU BBP01THE, a single row should appear with a blank nickname.
Solution provided:
-
Iteration Over Data:
- For-Each Loop at the ‘Root’ Level: The mapping begins by iterating through the “orderItems” element at the root level of the input data. This is to ensure that each SKU is processed individually.
- Nested For-Each Loop at the ‘Record’ Level: Within each order item, a secondary for-each loop is applied to iterate through the “studentData” array. This loop is responsible for handling individual student names, so each name can be mapped to its corresponding row in the output.
-
Field Mapping and Clone Creation:
- Mapping of Other Fields: Other relevant fields are mapped as required by the transformation rules. This includes mapping the SKU and other attributes that might be needed in the output.
- Cloning the Record: After the mapping rules have been defined, the process involves creating a clone of the Record node using a clone option:
- Click on the three dots (ellipses) associated with the Record node and select the “Clone Node” option.
-
-
- Choose the number of clones (in this case, 1) and check the “Copy Mapping” option.
-
-
-
- Click on the “Create Clone(s)” button.
-
-
-
- The cloning process ensures that an additional record (denoted as Record[1]) is generated in the mapping.
-
-
Application of Conditional Logic:
- Textual Rule for Condition: The core of the solution lies in applying a condition on the cloned record (Record[1]). In the textual rule associated with this node, the mapping checks if the student data exists. If it does not, the rule forces the mapping to use the SKU value instead.
- This conditional rule is what allows the output to dynamically handle cases of missing student names by either showing the available nickname(s) or leaving the field blank if the array is empty.
- Condition: IFF CONDITION{ count(./studentData)=0} VALUE=[ 'TRUE']
- Save the mapping.
- Validation:
- Testing with Debugger: Once the mapping is fully configured, we recommend running it in a debugger.
- This step is helpful to verify that the output CSV matches the expected results.
Comments
0 comments
Please sign in to leave a comment.