Friday 10 September 2010

How To... Create and debug a state machine workflow in SharePoint 2010 using Visual Studio 2010 and c# Part 2

Part 2 – Modelling The Workflow States for our solution

This is Part 2 of 4 for creating a state machine workflow using SharePoint 2010 with Visual Studio 2010 and c#. To read the introductions please click here.To read part 1 click here

States of the workflow, we will have the following states:

  • InitialState
  • InDevelopment
  • InTesting
  • CompleteState
A workflow must have an initial state set and must have a completed state set.


Steps

  • Re Open your solution created in Part 1.
  • Select the WorkFlowDevJobs.cs Design tab.

The design canvas will show a graphical representation of all of our states, as you can see only one state exists and we need to model 4 states in total. The solution presents a state machine workflow canvas.



Add our missing states

  • From the toolbox select the Windows workflow v3.0 tab, then drag 3 additional states onto the canvas.






The two states on our left will be our initial and completed states and the two on out right will be our ‘InDevelopment’ and out’ InTesting’ states.

Setting up the workflow states

  • Rename the WorkFlowDevJobsInitialState to Init_State.
  • Select the state
  • Change the name property to Init_State in the properties Window.
  • Rename StateActivity1 to InDevelopment_State
  • Rename StateActivity2 to InTesting_State
  • Rename StateActivity3 to Completed_State
  • Save the changes

The diagram should now look something like this:




Notice the error at the bottom of the screen – we will address this next. The error is caused by us renaming the initial state name.

Set the Initialization and completed states.

  • Set Init_State as the initialization state by right clicking the initialization state on the design canvas and then selecting set as initial state. Notice the error should disappear when this is done.
  • Set the Completion_State state as the completed state by right clicking the completed state on the design canvas and then selecting set as completed state.
  • Save your work and rebuild the solution to make sure you get a clean build without any errors.

    Note: The different icons on the Init State and completed_state states.


Summary

So far we have created our Visual Studio 2010 SharePoint state machine workflow project shell, we have then performed some tidy up work within the project, then we configured our workflow states. In the next part we will look at coding the states and associated state activities.



Click here for Part 3

No comments:

Post a Comment