# Design a For Each Loop in Your Business Process

Complete the following steps to create the logic that causes your business process to iterate over the sequence of nodes in the Request for Quote XML document:

- To Add a For Each Node to Your Business Process
- To Select a Repeating XML Element Over Which to Iterate
- To Design the Activities in Your For Each Loop

To Add a For Each Node to Your Business Process

1. Click For Each in the Palette.
2. In Design View, drag and drop the For Each node onto the RequestQuote business process placing it immediately after the Sales Tax Calculation Needed? (Decision) node.
3. Press Enter to name the node For Each.

The Design View is updated to contain the For Each node:

To Select a Repeating XML Element Over Which to Iterate

1. In the Design View, double-click the For Each node to invoke its node builder.
2. In the node builder, click Select Variable. A drop-down list of variables (of typed XML) in your project is displayed.
3. Select requestXML (QuoteRequestDocument). The requestXML variable contains the repeating XML element over which you want to design the iteration logic. A representation of the XML in the requestXML variable is displayed in the Select Node pane. The repeating element is identified by .

4. In the Select Node pane, if not already selected, click +widgetRequest.

The Repeating Element and Iteration Variable fields are populated with the following data:

- Repeating element—Contains the following XPath expression, which when applied against the incoming XML document, returns the set of repeating XML elements:

    $requestXML/ns0:widgetRequest

- Iteration Variable—Contains the name of an iteration variable: iter_forEach1. At run time, the current element being processed in the For Each loop is assigned to the iteration variable.

5. Click the X in the top right-hand corner to close the node builder.

The iteration variable, iter_forEach1, is created and added to the list of variables in the Data Palette. This variable is of XML type WidgetRequestDocument.

To learn how the iteration variable is used in the For Each loop, see To Design the Create PriceList Node.

This step completes the design of the iteration logic for your For Each node. Note that in the Design View, the node is updated graphically to reflect the work you did to define the condition:

indicates that the design of the task on the node is complete, as compared to , which indicates that the design is not complete. indicates that an XML query is defined on the node.

To Design the Activities in Your For Each Loop

After you create the iteration logic in your For Each node, you must define the activity or set of activities performed during each iteration over the items in the list you created.

You add activities to the For Each loop by creating nodes within it that support your business logic. In the next step in this tutorial, you create a Parallel node, and design it so that the business process executes two sets of activities in parallel: the request for price, and the determination of availability for the items requested by the client. To learn how to design a Parallel node, see Step 8: Design Parallel Paths of Execution.

Related Topics

Business Process Variables and Data Types

Looping Through Items in a List

Grouping Nodes in Your Business Process