Branch Step & Copy Condition in WebMethods

 Branch :

In webMethods, the “Branch” step is used to create conditional branches within a flow service, enabling different paths of execution based on specified conditions. Here are the key points about the “Branch” step in webMethods:
  • Purpose: The “Branch” step allows you to define conditional logic within a flow service, directing the execution flow to different branches based on the evaluation of conditions.
  • Conditions: The “Branch” step supports multiple conditions, and you can define one or more conditions using expressions or variables.
  • Branch Outcomes: Each condition within the “Branch” step is associated with an outcome, which represents the path of execution to be followed if the condition evaluates to true.
  • Default Outcome: You can also define a default outcome that will be followed if none of the specified conditions evaluate to true.
  • Outcome Mapping: The outcome of the “Branch” step can be mapped to subsequent steps, allowing for different actions or processes to be performed based on the selected branch.
  • Multiple Branches: The “Branch” step supports multiple branches, providing the ability to handle complex decision-making scenarios with multiple conditions and outcomes.
  • Nested Branching: The “Branch” step can be nested within other “Branch” steps, allowing for hierarchical decision-making and the creation of more intricate conditional flows.
  • Placement in the Flow: The “Branch” step can be placed at any point within the flow service, allowing you to control the flow of execution based on the specified conditions.

Copy Condition :
In webMethods, the “Copy Condition” step is used to copy the result of a condition evaluation into a variable. Here are the key points about the “Copy Condition” step in webMethods:

  • Purpose: The “Copy Condition” step allows you to capture the result of a condition evaluation and store it in a variable for further use within the flow service.
  • Condition Evaluation: Prior to the “Copy Condition” step, you typically have a step or expression that evaluates a condition based on certain criteria or inputs.
  • Variable Creation: To capture the result of the condition evaluation, you need to create a variable that will hold the value.
  • Copying the Condition Result: In the “Copy Condition” step, you map the result of the condition evaluation to the desired variable. This is done using the mapping functionality provided by webMethods.
  • Placement in the Flow: The “Copy Condition” step is typically placed immediately after the step or expression that evaluates the condition. This ensures that the condition result is captured and available for subsequent steps.
Difference between Branch & Copy Condition :
  • Purpose :
    • “Branch” Step: The “Branch” step is used to create conditional branches within a flow service, enabling different paths of execution based on specified conditions.
    • “Copy Condition” Step: The “Copy Condition” step is used to capture the result of a condition evaluation and store it in a variable for further use within the flow service.
  • Functionality :
    • “Branch” Step: The “Branch” step allows you to define multiple conditions and their corresponding outcomes, directing the flow’s execution along different paths based on the evaluated conditions.
    • “Copy Condition” Step: The “Copy Condition” step focuses solely on capturing the result of a condition evaluation and copying it into a variable for later use. It does not affect the flow’s execution path directly.
  • Output :
    • “Branch” Step: The “Branch” step determines the flow’s execution path based on the evaluated conditions. It specifies which branch of steps should be followed based on the true or false outcomes of the conditions.
    • “Copy Condition” Step: The “Copy Condition” step does not affect the flow’s execution path. Instead, it captures the result of a condition evaluation and makes it available in a variable for subsequent steps to utilize.
  • Placement in the Flow :
    • “Branch” Step: The “Branch” step is typically used at decision points within the flow service, allowing for branching based on conditions and determining the subsequent steps to be executed.
    • “Copy Condition” Step: The “Copy Condition” step is used immediately after the step or expression that evaluates the condition. Its purpose is to capture and store the result of the condition evaluation.
  • Execution :
    • “Branch” step: In the branch step, when the conditions are evaluated, the control will move to the first step within the branch that satisfies the condition. The execution will continue from that step onward, following the specific branch of steps that corresponds to the true outcome of the condition.
    • “Copy Condition” Step:  In the copy condition step, the order of execution is not guaranteed. During runtime, all the copy condition steps will be evaluated, and the condition that satisfies the condition last will be considered for mapping. This means that the mapping will be based on the condition that evaluates to true at the end of the evaluation process.

Exercise -1 : Design a flow service that takes a string input and checks if the input is “HarmoniGate”. If the input matches “HarmoniGate”, the output will be populated with the value “Website detected”. Otherwise, if the input does not match “HarmoniGate”, the output will be populated with the value “Default value triggered”.
Ans :
Branch as Switch:

  1. Create a flow service with the name branchSwitchCondition.
  2. Let’s create two variables: inputStr to store the input string and outputStr to hold the resulting output.

  3. Add a map step to the flow and include a descriptive comment to clarify its purpose. Additionally, create two variables in the pipeline named response1 and response2 to store the respective responses.
  4. Hardcode the response1 variable with the value “Website detected” and the response2 variable with the value “Default value triggered”. This ensures that the variables are assigned the specific values as specified.

     

  5. Include a branch step in the flow and provide a relevant comment to describe its purpose. In the branch step, add the inputStr variable to the switch condition. This allows us to check the value of inputStr and determine the appropriate value to populate in the outputStr variable based on the condition’s outcome.

     

  6. Within the branch step, incorporate two map steps for mapping purposes. In the first map step, hardcode the value “HarmoniGate” at the appropriate level. In the second map step, set the level as $default to handle all other cases. This arrangement allows for proper mapping based on the condition outcome and the default scenario.

  7. In the first map step, map the outputStr variable to the value of response1, and in the second map step, map outputStr to the value of response2. Ensure that any unnecessary variables are dropped from the pipeline to maintain a clean and optimized flow.

  8. Now, let’s proceed to test our service by supplying the input string “HarmoniGate” to the inputStr variable. This will allow us to observe the output generated by the service for this specific input.

  9. Let’s proceed to test the second scenario by running the service without providing any input to the inputStr variable. This will allow us to observe the output generated by the service when no specific input is given.

 
Branch as If Condition:
  1. create a copy of the service and paste it into the same folder. Rename the copied service to “branchIfCondition“. 
  2. In the “branchIfCondition” service, remove the inputStr variable from the switch level. Instead, set the “evaluate” level to true, treating it as an if condition. This adjustment will enable us to evaluate the condition based on the provided input and execute the corresponding branch accordingly.
  3. Since we are using this branch as an if condition, we need to add the conditions at the map level. In the first map step, include the condition %inputStr%=”HarmoniGate”. For the second map step, there is no need to modify it as it is already set to the default condition. These adjustments ensure that the mapping is performed based on the specified conditions.

     

  4. Now, let’s proceed to test the service by supplying “HarmoniGate” as the input for the inputStr variable. This will allow us to observe the output generated by the service when the input matches the condition.

     

  5. Let’s proceed to test the second scenario by running the service without providing any input to the inputStr variable. This will allow us to observe the output generated by the service when no specific input is given.

     

Copy Condition :
  1. create a copy of the service and paste it into the same folder. Rename the copied service to “branchCopyCondition“. 
  2. To achieve the desired result, remove the branch step and replace it with a map step. We will be utilizing the “Copy Condition” step to capture the condition result and populate the outputStr variable accordingly.

     

  3. In the map step, map the response1 variable to the outputStr. When you click on the line connecting response1 to outputStr, you will notice the presence of “Copy Condition” properties. Add the condition %inputStr%=”HarmoniGate” in these properties. As a result, the color of the connected line will change to blue, indicating the conditional mapping based on the specified condition.

     

     
  4. In the map step, map the response2 variable to the outputStr. In the “Copy Condition” properties section, add the condition %inputStr%!=”HarmoniGate”. This ensures that the outputStr is populated based on the condition where inputStr is not equal to “HarmoniGate”.

     

     

     

  5. Now, let’s proceed to test the service by supplying “HarmoniGate” as the input for the inputStr variable. This will allow us to observe the output generated by the service when the input matches the condition.

     

  6. Let’s proceed to test the second scenario by running the service without providing any input to the inputStr variable. This will allow us to observe the output generated by the service when no specific input is given.

     

 

Congratulations! We have successfully achieved the desired output. I hope you found the process enjoyable and satisfying.

To obtain the source code, simply click on the download button below to initiate the package download. This will allow you to access and save the code files for further reference😊.
                                            
                                       

Download Package

 

 

 

Leave a Comment