Converting a List Into a Grouped List

You may need to convert a flat list of items into a more structured list. For example, you may have list of all orders that have been completed. You may want to organize that list so that you can group the orders placed by each customer. This scenario typically occurs when you retrieve records from a relational database and the records must be structured differently.

In this example, the schemas are the following:

The following procedure describes how to map the flat list of orders into a list grouped by customer ID.

Procedure 

  1. Choose the repeating element in the Activity Input schema that holds the grouped data. In this example, that element is Orders. Right-click on this element and choose Statement > Surround with For-Each-Group... from the pop-up menu. This is a shortcut to create a For-Each-Group statement with the Orders element as a child element and a Grouping statement to contain the element you wish to group-by.

    Adding the Grouping statement creates the $=current-group() element in the Process Data area. The Grouping statement creates the list grouped by the desired element, and the current-group() function allows you to access the items in the Requests repeating element that correspond to the group that is currently being processed.

  2. Drag the repeating element from the Process Data area to the For-Each-Group statement.

  3. Drag the element you wish to group by from the Process Data area to the Grouping statement in the Activity Input area. In this example, customerID is the grouping element.

  4. Map the current-group() element in the Process Data area to the repeating element Order under the Customer element in the Activity Input area.

    The default choice in the mapping wizard for this mapping is to create a For-Each. Choose this option in the mapping wizard.

    This creates an item in the Order list for each item in the current customer ID group that is being processed. The mapping wizard asks if you wish to map items with the same name in the current group and the orders group.

  5. Map the remaining element from the current-group() element into the desired element in the For-Each group. In this case, quantity would map to Quantity automatically, and Item must be mapped to ItemName.

  6. Map the customerID element in the Requests element into the Customer element in the Activity Input area.