Tutorial: Building Your First Business Process

     Previous  Next    Open TOC in new window    View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Step 7: Looping Through Items in a List

In this step, you create the logic to extract a list of items from the Request for Quote document received from a client, and begin the work of designing the business process to determine the price and availability of the items requested by the client.

A For Each node represents a point in a business process where a set of activities is performed repeatedly, once for each item in a list. A For Each node 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 iteration variable holds the current element being processed in the For Each loop, for the life of the loop.

This section includes the following topics:

 


Understanding XML Schemas and For Each Nodes

The business process you build in this tutorial is designed to start when it receives a Request for Quote XML document from a client. The Request for Quote document must contain valid XML, that is, XML valid against an XML Schema, specifically QuoteRequest.xsd. The QuoteRequest.xsd Schema is located in your application at the following location: Tutorial_Process_Application_WEB\Schemas.

In the preceding line, myapplications represents the location of your tutorial application.

Note: To make the Schemas in your project available in your business process, you must place them in a Schemas folder in Utility project which is currently Tutorial_Process_Application_UTILITY. A project is one of the types of folders project that Workshop applications can contain. The projects added to your BEA Workshop applications are represented in the BEA Workshop file hierarchy as child folders of your application folder. To learn about creating and populating projects in your BEA Products applications, see Related Topics.

XML Schemas in your application's Schemas folder are compiled to generate XML Beans. In this way, BEA Workshop generates a set of interfaces that represent different aspects of your XML Schemas. XML Bean types correspond to types in the XML Schema itself. XML Beans provides Java counterparts for all built-in Schema types, and generates Java counterparts for any derived types in your Schema.

In Step 2: Specify How the Process is Started, you created a variable (requestXML) to which the Request for Quote document (which your business process receives from a client) is assigned. When you work with such variables in the Design view, you work with a graphical representation of the XML Schema that is associated with the variable. The following figure is a graphical representation of the quoteRequest element in the QuoteRequest.xsd schema, against which the Request for Quote document from clients is valid:

Note the following characteristics of the QuoteRequest.xsd Schema:

The business process in this scenario dictates that each pair of widgetId and quantity elements received in the Request for Quote documents from clients is processed. This processing begins with a For Each node—each iteration through the For Each loop processes one of a set of widgetRequest items.

In this section, you design the For Each node to first extract a list of items (the widgetRequest items) from the requestXML variable, and then to perform an activity (or set of activities) repeatedly, once for each item in the list.

Related Topics

Creating and Importing Schemas Files

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
  1. Click For Each in the Node 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.
  4. 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.
  5. 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.
  6. Click Close to close the node builder.
  7. 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.WidgetRequest.

    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


  Back to Top       Previous  Next