Friday, July 27, 2012

Triggering a workflow when expiry date is approaching

Out of the box, SharePoint allows workflows or tasks to begin when a certain date is reached. However, there's nothing that will trigger a workflow when a date is approaching.  For example, I have a list of contracts that have expiry dates attached in a custom column.  I want an expiry notification to fire three months before that date.

I found a solution here - Item expiration reminders in SharePoint using workflow - but for some reason, the workflow didn't work as expected, possibly due to the structure of my data.  So I've made some changes, trimmed it a little, and present it below.

Only one additional column had to be created - named "Previous due date", it's a date column in which the workflow stores the current expiry date.  It may even be possible to remove this column entirely, but I've left it in to make it easier to check the progress of the workflow.

What the workflow does is: it stores a workflow variable called Alert Date, which is simply three months before the Expiration Date.  If the Expiration Date is after today, it will set the new column, "Previous due date", to the current Expiration Date, and also sets a workflow variable, "Original Due Date", to the Expiration Date.  It will then carry out two actions in parellel -

  • Wait for the Alert Date to be reached, and then send an email
  • Wait for the Expiration Date in the item to change, and then stop the workflow.
Since the workflow runs on change or create, we don't want the same workflow running multiple times on the same item because the item has been changed, so the second action takes care of that.

Here's the actual workflow:


7 comments:

  1. This looks great, and is basically how I implemented that solution as well. One question--why do you use Today rather than Current Item:Modified or Workflow Context:Date and Time Started? I'm always leery of using Today, maybe unnecessarily so.

    ReplyDelete
  2. Thanks for your comment! Not really thought about the alternatives to be honest. I've not run into any problems with using Today, but I've certainly no reason for using Today over another method.

    I suppose, for the purpose of this workflow, Current Item:Modified might introduce problems for me - I'm creating the workflow long after the list/library has been created and populated, and I'm activating the workflow on those existing items retrospectively. Although, the expiration date would still be greater than Current Item:Modified, so yeah, no reason, just convenience!

    ReplyDelete
  3. Actually, thinking about it, some of the existing items had expiration dates in the past - I didn't want these to trigger the expiration workflow when I activate the workflow retrospectively. So I suppose there's a reason.

    ReplyDelete
  4. Hey i just want to say your WF simplified makes a lot more sense than what the other guy posted on his blog. He didnt explain any of the columns and expected us to know what his list looked like already. TY for this!

    ReplyDelete
  5. Hi, i dont understand the part where expiredate is checked if its changed? Since orgininal due date is set every time workflow triggers. it will always be the same??

    Sorry if im confusing. Do i really have to cancel workflow if expire date is changed??

    ReplyDelete
  6. Hi
    what if i want to add other 2 additional alerts 60 & 30 Days also to notify the person in advance to renew his ID Card

    ReplyDelete
  7. Add -30 Days
    Add -60 Days
    Add -90 Days

    can you please guide me how to create the workflow and send notification mails using the SharePoint Designer

    ReplyDelete