![]() ![]() ![]() ![]() ![]() ![]() ![]() |
A frequently designed pattern in your business processes is one that specifies the performance of a set of activities once for every iteration of the flow over a sequence of XML elements, retrieved from an XML document.
For Each nodes represent points in a business process at which a set of activities is performed repeatedly, once for each item in a list. For Each nodes includes an iterator node (on which a list of items is specified) and a loop (in which the activities to be performed for each item in the list are defined). An XML document (or a section of an XML document) is passed into the For Each loop in a business process variable. An iteration variable holds the current element being processed in the For Each loop, for the life of the loop.
This section describes how to add this looping logic to your business process. It includes the following topics:
The Design view is updated to contain a representation of the For Each node as shown in Figure 12-1.
Note the following characteristics of the For Each node:
Before you can add the logic that causes the iteration over a sequence of XML nodes in your business process, your project must contain an XML Schema or MFL file that defines the repeating XML or MFL element over which you want your business process to iterate. To learn how to import an XML Schema or MFL file into your project, see Creating and Importing Schema Files.
After importing an XML Schema or MFL file into your project, you can complete the design of the For Each node. It includes the following tasks:
The For Each node only iterates over repeating elements. The node builder allows you to select a repeating node from the variable you created in the preceding section.
For example, if we import an XML Schema (QuoteRequest.xsd
) into our project, and create a business process variable (requestXML
) of type quoteRequest
(based on the QuoteRequest.xsd
schema), the requestXML
variable is available in the drop-down list of business process variables as shown in Figure 12-2.
Note: | To learn about creating business process variables and importing schemas to your project, see Business Process Variables and Data Types. |
The Create Variable dialog box opens.
The Create Variable dialog box closes and your new variable is displayed in the Select Node pane.
Arepresentation of the XML in the requestXML
variable is displayed in the Select Node panel, see Figure 12-3.
Note the following characteristics of the QuoteRequest.xsd
schema as displayed in the preceding figure:
QuoteRequest.xsd
) specifies a root element named quoteRequest
.customerName
, shipAddress
, and widgetRequest
. shipAddress
element specifies the following attributes: street
, city
, state
, zip
.widgetRequest
element is a repeating element.
There can be one or more occurrences of the widgetRequest
element in an associated XML document; this is represented by in the GUI representation of the schema. The
widgetRequest
element, in turn, contains two elements: widgetId
and quantity
.
Note: In the example in the preceding figure, the repeating XML element (one or more occurrences) is represented by in the GUI representation of the schema. A repeating XML element that specifies zero or more occurrences is represented by
.
The Repeating Element and Iteration Variable fields are populated with data:
$requestXML/ns0:widgetRequest
. This expression returns all the widgetRequest
elements in an XML document.iter_forEach1
, by default. You can change the name by entering a new name in the Iteration Variable field.In the Design view, note that the icon in your For Each node displays the following graphics:
You must define the activity or set of activities that are performed for each item in the list you created in the preceding step ( To Select a Repeating XML or MFL Element Over Which to Iterate). Each iteration of the For Each loop executes the activity or activities you specify in a node (or nodes) in the loop.
As you drag a node onto the For Each loop, a target appears on the loop, representing a valid location in the For Each loop where you can place the node. As you drag the node near the valid location, the target is activated
and the cursor changes to an arrow
. You can release the mouse button and the node snaps to the For Each loop.
Grouping Nodes in Your Business Process
![]() ![]() ![]() |