Wednesday, August 19, 2009

How to create a SharePoint State Machine Workflow: Part 1 - Introduction

A while back I was tasked with creating a SharePoint workflow that would enable peer review of a document. (BTW, this whole article series will be all about creating workflows with Visual Studio, not SharePoint Designer.) An initiator would assign the workflow to a document in a document library and set who they wanted to peer review it. Now, if you've searched the internet for SharePoint workflows, you've undoubtedly seen that one sequential workflow that always pops up in examples. The problem is that sometimes a sequential workflow doesn't cut it - you just might need a state machine workflow. Imagine having a workflow where someone wants to send a document out for approval to three people sequentially, like a manager, a division director, and a department director. After the manager approves it, it goes to the division director, then when that person approves it, the department director gets it. But what if the division director rejects it? You might want it to bounce back to the manager. Similarly, if the department director rejects it, it goes back to the division director. The state machine workflow is the way to do this as each person will be a state.

This will be a six part series on how to create a SharePoint state machine workflow, although only the first four parts are necessary to create a functioning workflow
.
This example will employ a simple peer review model. An initiator will start a workflow on a document in a document library, assigning the person they want to act as the peer reviewer in the Initiation form. The workflow then starts. The peer reviewer will get a task. If the peer reviewer approves the task, the workflow is complete. If the peer review rejects the task, the initiator will get a task. In theory, the initiator could make changes to their document, and once they are done, they would approve the task, thus moving the flow back to the peer reviewer again. Once again, the peer reviewer would need to accept the task (which ends the workflow) or reject it (which sends the flow back to the initiator).

You are currently reading Part 1 of this series.
Part 2 will focus on using InfoPath to create the workflow's Initiation form.
Part 3 will focus on using InfoPath to create the workflow's Task form.
Part 4 will focus on creating the state machine workflow itself.

After part 4, you will have a fully functioning workflow. The following two parts are more like enhancements, but you'll likely want them.

Part 5 will focus on adding workflow history logging to the workflow.
Part 6 will focus on adding task notification emails to the workflow.

4 comments:

  1. D-J,

    Just wanted to say thank for taking the time to make this post. I've been going through a painful process of trying to learn State Machine Workflows on my own. Your step by step instructions really helped walk me through the process. This isn't exactly what I'm trying to achieve, but the step by step instructions you provided has provided me the guidance and code tips for achieving what I need to get done. So a serious THANK YOU for taking the time to share. Hopefully I will get good enough at this to do the same.

    Ink

    ReplyDelete
  2. Thanks very much for putting this useful info together

    ReplyDelete
  3. 1) is it possible to create a parallel state of activities in this state machine?
    if yes, can you pls help here?

    2) can we create dynamic tasks, when workflow is in runtime?
    my approver will select one many number of users from a dropdown and assign a single document for review.
    how to draw this kind o scenario in state machine!
    an help is highly appreciated.

    ReplyDelete