NOTE: This is a workaround to mimic state-machine behavior from a sequential workflow developed using SharePoint Designer 2007.
To get up to speed with developing SharePoint workflows using Visual Studio 2005, watch the HOWTO: Series of SharePoint Workflow HOW-TO Videos by Robert Shelton.
Sequential workflows are fairly straight forward to create whether you are developing in Visual Studio (VS) or SharePoint Designer (SPD) 2007 and can be used to model most single or multi-step approval workflows. The only downside to Sequential workflows is that you cannot make the workflow jump back to a previous step/activity that may or may not have already executed or, in other words, cannot move from being in one state to the other like a state machine workflow. For most workflow developers/creators, this is reason enough to go for workflow development in VS. While VS worksflows work just the same as those develped using SPD 2007, keep in mind that SPD 2007 is more suited for managers and/or business analysts (non-developers) who may be reluctant to assign workflow development task because of time, resource, and budgetary constraints. This is where the following intuitive solution may come in handy. Lets look at a hypothetical scenario in detail.
A technical document needs to be analyzed, revised (if need be), and approved to exist in the repository.
- Repository Managers
- Content Analysts
Workflow (see state-machine diagram above):
- Document Uploaded to MOSS 2007 Document Library. [Document Status updated to Awaiting Assignment]
- Repository Manager assigns document to Content Analyst. [Document Status updated to Pending Analysis & Review]
- Analyst views documents, makes required changes, and submits document to Manager for approval. [Document Status updated to Awaiting Approval]
- If Manager rejects document, document routed to Content Analyst. [Document Status updated to Pending Analysis & Review]
- If Manager approves document, it is kept in the document library. [Document Status updated to Approved]
The above workflow is pretty straight-forward, and could easily have been created using SharePoint Designer if it were not for step 4, which can happen any number of times until the document gets approved by the Manager. To create a State Machine behavior in a SPD 2007 workflow, create a separate list (say "Content Approval Workflows") to maintain the state of the workflow at any given point in time. A separate list also ensures that the user cannot go and manually change the status. Also, 2 workflows would need to be created; one on the actual document library (called "Core.NET Content") that houses the uploaded documents, and the other on the Content Approval Workflows list. The 2 lists we are working with are summarized below:
List Type: Document Library
Workflow Name: Approval Initiation Workflow
Workflow Executed: On Item creation
Core.NET Approval Workflows
List Type: Custom List
Workflow Name: Approval Processing Workflow
Workflow Executed: On Item creation
; On Item update
Columns: Title, Document Status (Choice Column with each of the workflow states), WorkflowInstance Id (Lookup column that references ID column in the Core.NET Content document library)
To get an even better idea, take a look at the following diagram.
The steps modeled in the diagram above are:
- Document uploaded to Core.NET Content Document Library.
- Item creation in Core.NET Content Document Library kicks off Approval Initiation Workflow which creates an item in the Content Approval Workflows list (with the Document Status value set to "Awaiting Assignment") and completes.
- Creation of item in Content Approval Workflows list kicks off the Approval Processing Workflow that performs the following operations recursively i.e. completion of every step below updates the Document Status column value and in-turn starts another Approval Processing Workflow instance on the same item.
- Start on item creation - If Document Status is "Awaiting Assignment", create a task in the Tasks list for Repository Managers, using the "Collect Feedback from user" activity, assign the task to the username entered in the task, and set the Document Status value to "Pending Analysis & Review".
- Start on item update - If Document Status is "Pending Analysis & Review", create a task in the Tasks list for the user in the Content Analysts group who was assigned the Analysis & Review task in the preceding step, using the "Collect Feedback from user" activity, and set the Document Status value to "Awaiting Approval" when the user clicks the "Complete Task" button.
- Start on item update - If Document Status is "Awaiting Approval", create an approval task in the Tasks list for Managers using the "Collect Feedback from user" activity, to either approve or reject the document. If Manager approves the document, set the Document Status value to "Approved", else set the Document Status value to "Pending Review & Analysis" which re-starts the workflow from step 3-2.
Note: The IF condition on every step ensures that the workflow takes only one path depending on the value for Document Status. Also, using the "Collect Feedback" activity in SPD 2007 ensures that the workflow stay in the wait state until the actor specifies the required input, and clicks the "Complete Task" button.
[UPDATE: Read the process of creating the State-machine workflow using SharePoint Designer 2007 in the following post here]