Mann Software
Mann Software > SharePoint and the Office System > Posts > Custom Workflow Status
Custom Workflow Status

A question on the SharePoint Forums prompted this write up...

A little known feature of SharePoint workflows is the ability to establish your own "Status" values for your workflow. By default, the following enum lists the values for SPWorkflowStatus:

 

public enum SPWorkflowStatus

{

Completed = 5,

ErrorOccurred = 3,

ErrorOccurredRetrying = 7,

FailedOnStart = 1,

FailedOnStartRetrying = 6,

InProgress = 2,

Max = 15,

NotStarted = 0,

StoppedByUser = 4,

ViewQueryOverflow = 8

}

The only one that is not really clear is "StoppedByUser" - this typically means that the workflow was Terminated through the UI.

The cool part of this is that you can specify your own values for a Status by adding entries to the workflow.xml file:

 

<MetaData>

<ExtendedStatusColumnValues>

<StatusColumnValue>Custom Status 1</StatusColumnValue>

<StatusColumnValue>Custom Status 2</StatusColumnValue>

</ExtendedStatusColumnValues>

</MetaData>

 

To set your workflow to a custom status, you need to add a State activity (the one from the SharePoint group, not the one that is for State Machines) and set it's State property to the integer value for the status you want. For the default values from the SPWorkflowStatus enumeration, the proper integer value is easy. For your custom statuses, you need to understand how your custom statuses are handled. Basically, the SPWorkflowStatus.Max value is equal to 15, as shown above, and this is where your custom statuses are added, treating them as a 0-based list. So, the first new value you add in workflow.xml has an integer value of 15 (SPWorkflowStatus.Max + 0), the second 16 (SPWorkflowStatus.Max + 1), etc.

The last part, and the actual question that prompted this from the forums is how do I retrieve the status? The trick here is that the status is a value added to the SPListItem the workflow is running on. Therefore, the following code will retrieve you an integer value (which follows the numbering scheme from above) for the value of your workflow on a given SPListItem:

SPListItem itm = <code to retrieve the SPListItem you are interested in>;

Int iWorkflowStatus = itm["<Name_of_Your_Workflow>"];

That's it. You can now make and use the status values you need for your workflow.

Comments

There are no comments yet for this post.
SharePoint Server MVP Community Kit for SharePoint Philly Office Geeks ISPA