The following is based on Beta 1 of WF 4.0 and as such might change or be missing in futures releases.
In Part 1 of this series of articles on WF 4.0 we started by looking at the new Sequential Workflow Designer, and creating a basic Sequential Workflow that added greeted a User. In this second part we will be looking at the new Flowchart Workflow and its designer.
So whats a Flowchart Workflow?
The Flowchart Workflow is a new hybrid of the Sequential and State Machine Workflows that we are already familiar with from 3.x. Even though WF was designed to be extensible so that people could extend it with their own custom Workflows, Microsoft found that a very large percentage of their customers using WF were bending over backwards to crowbar their Workflows into either the Sequential or State Machine types when neither were appropriate. From this Microsoft identified the need for a hybrid type, and this is the result.
So what do you use it for? This is easier to follow if we define when you’d want to use a Sequential and State Machine Workflow first.
So when do you use a Sequential Workflow?
The Sequential Workflow is ideal when you want to model a process that has a defined start and end points and follows a defined (linear) path through a number of Activities. Here’s an example:
So when do you use a State Machine Workflow?
The State Machine Workflow is ideal when you want to model a process that doesn’t have a defined path and could be one of many paths that will be taken through the Activities. A State Machine does not necessarily need an End Point. Here’s an example we’re all familiar with.
The State Machine was for Version Control, and as we all know there is no definite path as to how we perform our check in/check outs. One of the best uses for the State Machine Workflow is for Lifecycles of objects, where we have a defined number of States an object can be, in but the direction of state changes comes from an external source.
What about this new Flowchart Workflow?
So hopefully you’ve now got some idea as to what the original Workflows could do and where they might be used. We can now take a look at the Flowchart Workflow. One of the biggest differences between 3.x and 4.0 is that there is no longer any restriction on which kind of Workflow an Activity can be used on, so our Flowchart Workflow can use exactly the same activities as we did on the Sequential example.
So first off the designer.
As you can see we have the same features as before from the Sequential designer, but this time we have different rules as to how the Activities interact. First off we no longer get connections for free between activities. This is of course down to the nature of the Workflow type, as the designer can’t guess what Activities we want to join together and how. So to join Activities together we select the start Activity and then drag one of the edge connectors to the target Activity’s edge connector.
Again Variable and Arguments are used in exactly the same way as we did with the Sequential Designer. The Flowchart Workflow currently comes with 3 extra Items (not Activities) that allow us to add decision logic into the Workflow. The first is the FlowDecision which acts as a simple If statement in the logic.
This is actually a very simple Item to use, again dragging from either the green True connector or red False connector to another Activity will give you the path when either a True or False result comes from the Condition you set. The Condition is something that evaluates and returns a boolean result. So far I’ve been using things like VariableName.Equals(“StringToMatch”) for the condition. I suspect that in future releases this may have some sort of Expression Editor to it (but this is just my speculation).
The second new item is the FlowSwitch, and looks very similar to the FlowDecision.
OK, so lets put this altogether. I’m going to create a simple Workflow for Pizza management at User Group talks. It’s going to ask us our location, if its the home region of Southampton then it’ll tell me I need to order Pizza. If it’s not Southampton, I’m doing a WF talk somewhere else so I remind the User Group leader. Then because I could in theory be doing a marathon number of talks in one day, it’ll ask if my location has changed and if it has we go back to the beginning, otherwise the flow end.
A screen cast with the construction of the Pizza Flowchart, will follow shortly.
In Part 3, we will be looking at creating a custom Activity.