The following procedure 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.
The first part of the procedure guides you through creating a loop. The second part of the procedure details how to set up iterating over instances, which completes the task.
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 on the Business Process canvas to activate the Tool Palette.
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 or open the Variables Panel view.
The Business Process Variables section of the Business Process editor is the default. For the rest of the procedure, we will refer to it, but you can use either.
Select Local Variables, right-click, and select New Variable from the context menu.
Expand Properties or open the Properties Panel view.
The Properties Panel view is the default. For the rest of the procedure, we will refer to it, but you can use either.
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 Expression canvas.
From the Node Set Functions tool palette, select Count and drag and drop it onto the Expression canvas.
From the Number Functions tool palette, select Round and drag and drop it onto the Expression canvas.
Connect the activities:
Connect the repeating node to Count.
Connect Count to Round.
Connect Round to the target.
Select File|Save from the main menu bar.
Select the Complex activity to display its properties and in the Properties Panel, do the following:
Select the Iteration Settings tab.
Select This activity runs iteratively.
Click
in the Counter variable field and select the local variable that you defined,
loopcounter, as the X for the number of elements.
Click
in the Counter initial field, select Literal, enter 1, and click OK.
Click
in the Counter increment field, select Literal, enter 1, and click OK.
In the Expression canvas, which is labeled Loop termination condition:
Drag the counter variable, loopcounter, from the Business Process Variables section and drop it onto Select Variable.
Select is equal to, right-click and select Delete from the context menu.
Click on the Expression canvas to activate the Tool Palette.
From the Boolean Functions tool palette, select is less than and drag and drop it onto the Expression canvas.
Select string constant, right-click and select Delete from the context menu.
From the Business Process Variables section, drag the local variable called countnodes onto the Expression canvas.
Connect the activities in the expression:
Connect loopcounter to the top connection of is less than.
Connect the local variable countnodes to the bottom connection of is less than.
Collapse the expression.
The expression should read something such as, loopcounter is less than count nodes. This has the Loop activity perform its task sequence one time for each element of items.
To set up iterating over instances:
In the following steps, you will finish defining the Complex activity that you created in step 4 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 on the Expression canvas.
In the Properties for the Operation,which is on the right side of the Expression canvas, click Advanced.
The XPath Workarea opens.
Find the repeating node in the XPath, put the cursor after this node, and type [/loopcounter], and click OK.
This assigns the data to the target for further processing.
Send your feedback on this help topic to Sybase Tech Pubs: pubs@sybase.com