New Workflow Events
Last modified: April 16, 2010
Applies to: SharePoint Foundation 2010
Workflows can respond to events around them, but they cannot emit events themselves for other event receivers to listen to. This fact means that one workflow cannot listen to other workflows, and other events cannot listen for workflow errors. However, in many instances this behavior would be beneficial. For instance, if a workflow had the ability to start another workflow, a developer could add a step to the end of the approval workflow. This ability has the effect of making workflows modular and allowing reuse of existing code. Also, adding pre-event handlers to workflow events helps developers add validation that prevent schema or serialization errors before they happen, and provide a means for communicating with administrators when something was wrong.
Along with the added number of events, a developer can now create custom events and event receivers to handle special circumstances.
In Microsoft SharePoint Foundation 2010 developers can write event handlers for workflows by using the same model they use for other SharePoint events.
Developers can write workflows that call other workflows and wait for them to finish.
Developers can upgrade workflow instances "on the fly" by interjecting additional code into an existing workflow, thereby diverting existing code into new code.
Like any event receiver, workflow event receivers can be registered by using SPWeb (which listens for events on any workflow running in the site, including site workflows), SPList (which listens for workflow events on any workflow running on an item within that list), or SPContentType. (Content type event receivers should trigger only when the workflow event is fired from a workflow running on a document of that content type.) Also, withSharePoint Foundation 2010, developers can add receivers to SPSite.
To create a workflow event receiver, a developer overrides the SPWorkflowEventReceiver class and implements the events to trap.
The developer registers the receiver for workflow events by using the standard SharePoint event receiver model, which uses a SharePoint Feature solution to package and install the event receiver or register the event receiver by using the object model.