The procedure in this topic is an example of how to set up an
expression that allows a business process to perform a specific action for each
item in a list.
For example, when an order is processed to perform a specific action
for the type of product purchased in the order, you must create a complex
activity that can be used to iterate through x number of items. You would
create a loop in the business process that performs an action for each item in
a list of repeating items and terminates when the count exceeds the number of
items in the data.
To set up looping:
- Create a business process
service that uses data with repeating nodes.
An example of this is an order item that contains details about
the item, such as, its ID, name, color, and price.
- In your business process,
select the
Business Process tab.
- Click in the Business
Process canvas to activate the Tool Palette.
Note: If the Tool Palette does not appear either on the Fast View
shortcut bar or as an open view in the perspective, open the Tool Palette.
- From the Activities tool
palette, select the
Complex activity and drag and drop it onto the
canvas.
In the following steps, we will define Complex activity that loops
to check each item and do some type of activity. An example of this is, if the
item color is blue, you could have an e-mail sent to marketing so they know
this color is selling.
- Expand the Business
Process Variables section.
- Select
Local Variables, right-click, and select
New Variable.
- Expand Properties.
- Select the default name
and, for this example, type
loopcounter
in the
Name field.
The variable must be an integer, which is the default.
- Create a second local
variable and type
countnodes
in the
Name field.
- From the Activities tool
palette, select the
Assign activity and drag and drop it onto the
canvas before the Complex activity.
- From the Properties Panel
view, drag the nodes to be counted and drop it into the
Source cell of the
Assign.
- Drag the
countnodes variable and drop it into the
Target cell of the
Assign.
- Select the
Assign tab and click on the canvas.
- From the Node Set
Functions tool palette, select
Count and drag and drop it onto the canvas.
- From the Number Functions
tool palette, select
Round and drag and drop it onto the canvas.
- Connect the activities:
- Connect the
repeating node to
Count.
- Connect
Count to
Round.
- Connect
Round to the target.
- Select
from the main menu bar.
- Select the Complex
activity to display its properties and in Properties, do the
following:
- Select the
Iteration Settings tab.
- Select
This activity runs iteratively.
- Click the ellipse
in the
Counter variable field and select the
local variable that you defined,
loopcounter
, as the X for the number of elements.
- Click the ellipse
in the
Counter initial field, select
Literal, enter
1
, and click
OK.
- Click the ellipse
in the
Counter increment field, select
Literal, enter
1
, and click
OK.
- Drag loopcounter onto the Xpath editor.
- Position the cursor at the end of loopcounter, right-click, and select .
- Position the cursor at the end of < and drag countnodes
onto the XPath editor.
To set up iterating over instances:
In the following steps, you will finish defining the Complex activity
that you created above.
- Click on the Business
Process editor canvas to activate the Tool Palette.
- From the Activities tool
palette, drag
Assign and drop it into the looping Complex
activity.
- From the Business Process
Variables section, drag the repeating element that contains the data you want
to use and drop it into the
Source cell of the
Assign.
- Drag the parameter you
want to send the data to and drop it into the
Target cell of the
Assign.
- Click the
Assign
tab.
- Select the source
parameter.
- Find the repeating node
in the XPath, put the cursor after this node, type
[/loopcounter]
and click
OK.
This assigns the data to the target for further processing.