views:

357

answers:

1

I have a fairly straight-forward sequential approval workflow that has an EnableModificationActivity that is in scope for just about the entirety of the workflow. My modification form is an ASPX page that gives the user the ability to enable/disable approval steps that have not occurred yet in the workflow. Since the workflow is able to be modified multiple times, I would like to the form to reflect the current state of the workflow, meaning it should show which activities are currently enabled or disabled.

I have come up with a clunky solution for this that I will share a little later on, but I have got to believe there is a clean way to go about this.

A: 

So here is the approach I ended up taking...

  1. I created a Plain Old CLR Object (POCO) class specific for holding state information my particular workflow that is capable of being XML Serialized. I'll call this the "State Object" going forward.

  2. I created a reusable class called "WorkflowStateManager" that is capable of loading and saving single State Objects for a given SPWorkflow. This class is accessible by both the workflow and the modification form.

    • Save State Implementation:
      1. XML serializes the object to a string
      2. Sets the serialized string on the SPWorkflow list item's property bag and calls the property bag's Update() method
    • Load State Implementation (Essentially the reverse of the Save State implementation)
      1. Gets the serialized string from the SPWorkflow list item's property bag
      2. XML Deserialize the string into the State Object
  3. When the workflow is activated, I construct a new State Object, initialize various properties on it, and save it using the WorkflowStateManager.

  4. As the workflow progresses, I load and update the State Object as needed in the following manner:

    • Use the WorkflowStateManager to load the current State Object
    • Make workflow decisions based on the State Object's values
    • Make desired changes to the State Object
    • Use the WorkflowStateManager to save the State Object
  5. Now, my modification form is also able to load, manipulate, and save the State Object using the WorkflowStateManager, and in turn expose the current state of the workflow to the user.

I hope this might be of benefit to someone.

Trent