Duration: 10 minutes
This tutorial introduces the BRANCH operation, which supports conditional processing. In this tutorial, you will apply conditional logic to grant a 20% discount to a premium customer.
Note: The BRANCH operation is analogous to an “if-then-else” statement in languages such as Java.
Prerequisites #
This tutorial builds on concepts, techniques, and objects covered previously in:
- 1. Create an IS Package and Folders
- 2. Create and Run a Flow Service
- 3. Create Document Types
- 4. Create a LOOP Operation
- The tutorials above must be completed or you can import the solution: Completed Export of 4. Create a LOOP Operation.zip using these instructions: Import an IS Package
- The IS must be started. Instructions on how to start the IS are found in the Prerequisites part of the 1. Create an IS Package and Folders FLOW tutorial.
Step Outline #
You create the BRANCH operation by:
- Adding the BRANCH step to the service
- Setting the BRANCH condition
- Adding logic to perform a transformation when the condition is met
Step 1: Add Conditional Logic to the Data Mapping Service #
In this step: You will add a BRANCH step to the previously created data mapping service, OrderRequestToOrderResponse.
To add a BRANCH step:
- Open the data mapping service FLOW_Tutorial.services:OrderRequestToOrderResponse
The BRANCH tool enables you to change processing based on conditions that you set within the BRANCH properties.
- add a BRANCH step below the MAP step that is a child of the LOOP step:
Designer creates the BRANCH step and displays its Properties:
- Set the Switch property of the BRANCH step to Request/Request/Orders/SKU:
Important: If you copy the Request/Request/Orders/SKU element from the Pipeline tab, you must copy it from within the LOOP step; for example, select the nested MAP step, select the Pipeline tab, then select the element.
Designer displays the configured BRANCH step:
Note: In this step you used a literal string to create the BRANCH label; however, you can set BRANCH labels using more complex and dynamic operations, such as regular expressions.
You can now add transformation logic to the BRANCH operation.
Step 2: Add Transformation Logic #
In this step: You will add a transformer, and configure it to apply a discount under a specified condition.
To add transformation logic to the service:
- Add a new MAP step under the BRANCH:
Note: Ensure that the step is nested correctly so that it is a child of the BRANCH step.
- Set the Label property of the new MAP step to 01:
Designer displays the new MAP step (you can click the enter button or select anywhere within the flow editor to see the MAP step update:
- Add a description to the MAP step in the Comments property and click Enter, for example:
Apply 20% discount for this item
Designer displays the new MAP step:
- In the Pipeline Editor, add the Transformer pub.math.multiplyFloats to this MAP step
- Expand the Transformer, then map the following inputs:
Response/Response/Orders/AmountDue to num1
- Map the Transformer output value to:
Response/Response/Orders/AmountDue
You can now set the value of transformer input and output using the Set Value tool.
To set the value of the transformer input:
- Select num2 in the pub.math.multiplyFloats Service In column, then select the Set Valuetoolbar button:
(alternatively, you may double-click num2 to set its value)
Designer displays the Set Value dialog.
- Set the value of num2 to 0.8, and click OK.
Note: The value of the discount itself is hard-coded, not conditional.
The num2 input to multiplyFloats will now reflect a set value, which may be revealed by hovering the cursor above the set value icon.
- Save and Run the service using the same input file as in the previous tutorial:
Note: You may need to re-load the input file:
Designer displays the data loaded from the input file.
- select OK
Designer displays the Results, showing the discount applied only to SKU 01:
150 * 20 * 0.8 = 2400
The Results show that the discount is not applied to the other orders (no 20% discount):
50 * 12 = 600
Conclusion #
You have enhanced the service by incorporating conditional logic to apply a discount to a specified item.
To import the solution of this tutorial download Completed Export of 5. Create a BRANCH Operation.zip and follow the directions in the Import an IS Package tutorial.
Read in this series:
- webMethods Flow Tutorial - No.1 Create an IS Package and Folders
-
webMethods Flow Tutorial - No.2 Create and Run a Flow Service
-
webMethods Flow Tutorial - No.3 Create Document Types
- webMethods Flow Tutorial - No.4 Create a LOOP Operation
-
webMethods Flow Tutorial - No.5 Create a BRANCH Operation - Current tutorial
- webMethods Flow Tutorial - No.6 Create a SEQUENCE Operation
- Import an IS Package
-
File Drop Tutorial
- Flat File Processing Tutorial
-
webMethods JDBC Adapter tutorial - Create a JDBC Adapter Service
-
webMethods SAP Adapter Tutorial
- Integrate with Salesforce.com using the CloudStreams Adapter