Using If/Else activity in Workflow Foundatio
In this post I will explain how to utilize the IFElse activity and a declarative condition in the workflow to perform the conditional processing.
This workflow evaluates the order by taking the order value and if the order value < $1000 then it will approved by Manager other wise it requires vice president approval.
1. Create a new workflow project by selecting File->New->Project menu command visual studio displays the New Project dialogue window.
2. Select the Empty Workflow Project template from the dialogue box and say ok.
3. Add the new item to the empty workflow project and select the Sequential Workflow (with code separation) template from the above dialogue box.
4. Start the workflow by writing the following code in Main program.cs file.
In above code we have started the workflow runtime and loaded the workflow type that we are going to design in the next step.
Notice that we are also passing the OrderValue as the parameter to the workflow.
5. Add the IF/ELSE activity to the workflow designer from the toolbox.
6. Add the condition to the ifElseBranch1 by selecting the ConditioName from the properties window.
7. Similarly Add the condition to the ifElseBranch2 by selecting the condition name from the properties window.
8. Add the code activities below the both ifElseBranch1 and ifElseBranch2 branches and attach the event handlers to the ExecuteCode property.
9. The code besides file of the workflow will look like
10. You can attach the ManagerApprovalHandler to one branch and VPApprovalHandler to another branch by selecting the code activities and assign the value to the Executecode property.
11. You will see the following output after executing the application
We discussed about using the If/Else activity in workflow and evaluating the conditions using the activity. In the next post we discuss about other important activities in the workflow.