FoodBroker project: Collect and copy parts

The tool loop on instruction improves the efficiency of the expressions for generating the fax text. The following is an improved version of the expression:

%text := "";
loop on order:\order\line
{
   %text := %text + order:this\qty + " x " + order:this\!item! + "\n"
};
%text

Instead of being proportional to , now the time spent to process n occurrences is proportional to n, which is more practical.

Collecting and copying parts

In this expression, the text variable is used to accumulate the fax text. In order to use this variable, you need to define it first with class S (string). When evaluating the assignment, the integration engine sees the value of qty is needed which is a whole number (class I). To concatenate this value, the integration engine implicitly converts the whole number into a string.

You can also generate sets of occurrences from other sets of occurrences. For example, you can copy order lines and address lines from input to billing output.

For customer and supplier lines, you generate as many line nodes in the output as there exist line nodes in the input with the input values in them. To accomplish this, you use a for each…do… structure as the expression bounded to line in the Map:

for each order: \order\customer\address\line do this
for each order: \order\supplier\address\line do this

The first expression is for a line node which resides in the customer group. The second expression is for a line node which resides in the supplier group.

Expressions for line nodes

For line nodes in the order, the technique is quite similar: you use for each on the parent item. When processing the following expression, that is attached to the node line (node #33 in the following graphic), the integration engine generates as many occurrences of the output group line as there are occurrences of the input group line:

for each order: \order\line

This means that item (#34), qty (#35) and price (#36) nodes are generated using their expressions in the Map.

 item (#34), qty (#35) and price (#36) nodes are generated

In the preceding graphic, you can see how the copy is performed:

  • The expression for the parent line contains a for each statement that generates as many groups as needed
  • Each group member has an expression that generates its value from the current line node value in the input (referred to by the keyword this)

Notice the use of exclamation marks to keep the node name item from being interpreted as the keyword item.

If the incoming order from the web server includes empty lines (either empty items or zero quantities) and you do not want empty value nodes in the output Business Document, add a filter using a where clause:

Adding a filter using a where clause

The final node that you need to compute for both output Business Documents is the initial amount of the order. This is basically the sum of the line costs of each order, which for each line is the quantity multiplied by the unit price.

You need to go through all the occurrences of line, perform the multiplication, and accumulate the results in a variable that then represents order amount.

The following graphic illustrates appropriate expression bound to the amount node:

Expression bound to the amount node

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