# Designing Your Decision Node

To create logic for your Decision node, you must complete the following steps:

- To Design the Condition Logic
- To Add Activities to the Paths in Your Decision Node

To Design the Condition Logic

1. Double-click the Condition node to invoke the decision builder.
2. Select one of the options:

- Variable—Select this option if, at run time, you want the business process to make a decision, based on the value of an element in an XML or non-XML variable.
- Method—Select this option if, at run time, you want the business process to make a decision, based on a boolean result returned from Java code that you create.

The node builder displays different options depending on whether you select Variable or Method.

3. Complete the selections in the node builder appropriate for the selection you made in the preceding step: Variable (Schema) or Method.

Variable (Schema)

The following steps describe how to select a business process variable that is associated with an XML or MFL schema.

Note: To learn about creating business process variables and importing schemas to your project, see Business Process Variables and Data Types and Importing Files into the Schemas Project.

1. In the condition builder, select a business process variable by clicking .

A drop-down list of business process variables in your project is displayed.

For example, if you imported an XML Schema (QuoteRequest.xsd) into your project, and created 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.

2. Click the arrow in the Select Variable drop-down list, then select a variable that contains the XML or typed non-XML on which you want to build the condition.

A representation of the XML Schema associated with that variable is displayed in the Select Expression Node field.

The elements and attributes of an XML document, assigned to this variable, are represented as nodes in a hierarchical representation, as shown in the preceding figure. Note that the schema in the example (QuoteRequest.xsd) specifies a root element (quoteRequest), and child elements: customerName, shipAddress, and widgetQuoteRequests. The widgetQuoteRequests element, in turn, specifies a repeating element: widgetQuoteRequest. (A repeating XML element is represented by in the GUI representation of the Schema.)

3. In the Select Expression Node field, select the node in the XML Schema for which you want to define the condition.

To continue with the example, supposed you selected customerName from the XML variable represented in the preceding figure. The Selected Expression field is populated with the following expression:

    data($requestXML/ns0:customerName)

4. Click Select. Your new variable is displayed in the Left Hand Expression field.
5. Select an operator from the Operator drop-down list.

For example, =

6. In the Right Hand Expression field, enter a value or choose a variable and expression with which to create the decision logic.

For example, enter BEA.

7. Click Add. The condition you created is added to the condition list.

For example, data($requestXML/ns0:customerName = "BEA"

8. Select a join option of either AND or OR to qualify your conditions.
9. To add a condition based on an existing value in the Left Hand Expression field:

1. In the condition list pane, select a condition. The Left Hand Expression, Operator, and Right Hand Expression fields are populated with the appropriate values.
2. In the Right Hand Expression field, select the value.

For example, BEA.

3. Change the entry you selected.

For example, Avitek.

4. Select the arrow beside the Update button, then select Add from the menu.

The new condition is added to the bottom of the condition list.

10. To edit the conditions after you create them:

1. In the condition list pane, click the condition that you want to change. The Left Hand Expression, Operator, and Right Hand Expression fields are populated with the appropriate values.
2. Change the value in any of the fields.
3. Click Update.

Alternatively, you can edit conditions directly in the code. To do so, in the Condition builder, click View Code in the lower left-hand corner. The XQuery function that was written to the file from the design work in the condition builder is displayed at the line of code in your JPD file; it is indicated by the @jpd:xquery prologue annotation.

11. To edit Join Options after you create them:

1. In the condition list pane, click the Join Option that you want to change.
2. Select the appropriate join option.
3. Click Update.

12. In the Design View, click X in the top right-hand corner of the condition builder.

In the Design View, note that the Condition in your Decision node displays the following icons:

- is a visual reminder that the condition you defined on this node is based on the evaluation of an XML document.
- is a visual reminder that the condition you defined on this node is based on the evaluation of a MFL file.

Defining an XML or MFL condition produces an XQuery function that is written to your JPD file, which you can see in the Source View. The condition defined by following the preceding example (in steps 1 through 7) creates the following XQuery function in the JPD file:

    //* Process Language */

    * @jpd:xquery prologue::

     *   define function cond_requestXML_1(element $requestXML)
     *   returns xs:boolean {
     *         data($requestXML/customerName) = "BEA"

     *   }
     *   ::

13. To save your work, select File —> Save.

Method

The following steps describe how to select a business process variable that is associated with an XML or MFL schema.

1. In the Java Method Name field, enter a name for the Java method, or, to choose an existing method, click .
2. Click View Code in the lower left-hand corner of the node builder.

The Source View is displayed at the line of code in your JPD file at which the Java method is written.

3. Edit your Java method.
4. To return to the Design View, click the Design View tab.
5. Close the condition builder by clicking X in the top right-hand corner.

In the Design View, note that the Condition in your Decision node displays the following icon: . It is a representation of the condition you defined in source code that specifies the Java method on which to base the decision. To make any further changes to the condition represented on this node, you must edit the source code in the Source View.

6. To save your work, select File —> Save.

To Add Activities to the Paths in Your Decision Node

After you define the condition that is evaluated when the flow transitions to the Decision node at run time, you are ready to define the actions on the paths that represent the paths of execution in the flow.

1. Add a node (or nodes) to each path in the Decision node to define the activity that is executed when the conditions you defined on the Condition node at the beginning of the path evaluates to true.

This can be any node that performs an activity appropriate for your business process business logic. For example you can use a control to interact with an external resource, such as a database, a JMS queue, or an EJB.

2. Add a node (or nodes) to the default path that defines which activities are executed when no condition evaluates to true at run time. The nodes on the default path can be any that define activities appropriate for your business process business logic.

When you complete the addition of activities on the paths of your Decision node, your decision logic is represented as a series of conditions and actions in your business process.

Example Decision Node

The following figure shows an example Decision node in the Design View.

Building on the QuoteRequest example used in building the Variable (Schema) condition, two Perform nodes are added to the paths on the Decision node. At run time, the following sequence represents the flow of control in this decision node:

1. The condition defined on the Check Customer condition node is evaluated:

    data($requestXML/ns0:customerName = "BEA"

Note: The XML evaluated by the condition node is assigned to the requestXML business process variable.

2. If the Check Customer condition evaluates to true at run time, the activities defined on the BEA Orders node are performed, then the flow exits the Decision node.
3. If the Check Customer condition evaluates to false at run time, the path of execution is the Default path. The activities defined on the Non BEA Orders node are performed, then the flow of control exits the Decision node.

Related Topics

Creating a Decision Node in Your Business Process

Grouping Nodes in Your Business Process

Handling Exceptions

Adding Message Paths

Adding Timeout Paths

Business Process Source Code

Interacting With Resources Using Controls