Towards SharePoint Technical Design Patterns: SharePoint Designer Workflow + Event Receiver = High Potency Cocktail

One of the emerging patterns I find in crafting SharePoint solutions leverages SharePoint Designer workflow and an event receiver.

Here is a business scenario to put it in context:

  • I upload a document to a doc lib.
  • I kick off multi-step workflow created using SharePoint Designer.
  • At some point during that process, workflow assigns a task to someone (via collect data from user or assign a task).
  • We want to use a KPI to track how long that task is awaiting completion.  The KPI shows green for tasks that are completed or due more than 3 days from now.  It shows yellow if the task is due tomorrow or today.  It shows red if the task is past due.
  • Here’s the kicker: I want the date that drives that KPI to be holiday-aware.

I can’t calculate a holiday-aware due date in SharePoint Designer workflow very easily.  I would have to create a custom action or use a 3rd party tool.  However, it’s easy enough to calculate such a date in an event receiver.  Merge those two together and we get a pattern like this:

  • Define a hidden yes/no site column on the document library labeled "DoCalcualteDueDate".
  • Initialize it to false.
  • At the appropriate time in the workflow (e.g. just before the "collect data" action), assign that value to True.
  • An ItemUpdate() event receiver looks to see if "DoCalculateDueDate" is true.  Since the event receiver runs on every update, "DoCalculateDueDate" is normally false.
  • When workflow assigns DoCalculateDueDate to true, the event receiver calculates the holiday-aware due date.
  • When the event receiver does this calculation, it sets the DoCalculateDueDate flag to false.

In the end, SPD workflow is communicated with an event receiver via the DoCalculateDueDate semaphore and we have holiday-aware due dates that are assigned at the exactly correct moment in the workflow’s life.  SharePoint Designer controls when the due date is assigned but the event receiver performs the actual calculation and assignment.

</end>

Subscribe to my blog.

Leave a Reply

Your email address will not be published. Required fields are marked *