FoodBroker project: Introduction to data aggregation

The data that is sent to the restaurant order application includes a piece of text that contains the order. This text is actually the message body of the fax sent to the partner restaurant. This text is composed of lines that include the ordered dish and the quantity required. You can explicitly concatenate all the items using paths with the [] operator and string operator +:

order:\order\line[1]\qty + " x " + order:\order\line[1]\!item! + "\n" +
order:\order\line[2]\qty + " x " + order:\order\line[2]\!item! + "\n"

This expression works, but ignores order lines after the 2nd. This is not acceptable: you need to take into account all occurrences of the line node to build the complete text. A loop is needed. The expression that accumulates all the order lines into the text is:

%text := ""; %line_index := 1;
loop (count (order:\\line))
{
   %text := %text + order:\order\line[%line_index]\qty
            + " x " + order:\order\line[%line_index]\!item! + "\n";
   %line_index := %line_index + 1
};
%text

This works fine for orders with less than one hundred lines, but becomes less and less efficient as the number of lines grows. What is time consuming in such a structure is that the integration engine does not to detect that you actually want to pick up occurrences of line one after another. In this situation, each access to line restarts from the very first occurrence. The time needed to perform this loop on n occurrences is roughly proportional to n².

A better solution is shown in the next chapter.

Related topics

FoodBroker project: Do the first steps

Create a Business Document for the customer request

Create a Business Document for the partner

Create a Business Document for partner rates

Build the Mapping Flow

FoodBroker project: Fill headers

FoodBroker project: Determine the incoming order ID

FoodBroker project: Generate the order ID

FoodBroker project: First steps in filling nodes

FoodBroker project: Extra charge for VISA payments

FoodBroker project: Introduction to data aggregation

FoodBroker project: Collect and copy parts

FoodBroker project: Manage rates

FoodBroker project: Handle absence of partner rates

Related Links