SharePoint Designer Workflow Pause Until Date Change

So what happens when you’ve built out a SharePoint Designer workflow with a Pause Until Date activity, and then the date changes on you? Obviously, we want to the workflow to handle this situation and update the Delay logic accordingly.

Scenario

Let’s assume we have a Date Received column. After 2 weeks of initial item creation, we want to send a reminder notification to the user. So based on the value of Date Received column, add 14 days, and if Today matches that value, then send a notification. For this we need the Pause Until Date activity, so we do a quick evaluation, if there is a match, send the reminder, otherwise, pause until we reach that date.

  1. User enters Jan 13, 2012 in date received and creates new item.
  2. Workflow kicks off and determines that Jan 13, 2012 + 14 days is equal to Jan 27, 2012.
  3. Workflow checks if Today is equal to Jan 27, 2012. If it is, send the email reminder.
  4. If it isn’t, Pause Until Jan 27, 2012. You will see the pause activity log to the workflow history list the day it’s planning to pause until.

Perfect right, works great. Now what happens when a user edits the item and changes the date received to Jan 17, 2012. We want the delay to postpone until the 31st of Jan, not the 27th. I’ve read a great deal of posts that document how others have tackled this problem, ranging from an event handler to some sort of custom workflow logic. In our case, since the forms were custom ASP.NET forms submitting programmatically to the list, it was easy enough for me to track any changes to the date received column, and if I do find that it has changed, I simply stop and restart the workflow within the submit event. The logic looks like this:

// stop and restart the workflow if date received is different
if (dtcDateReceived.SelectedDate.ToShortDateString() != dateReceived.Value)
{
    // stop workflow
    SPWorkflowCollection itemWorkflowCollection= item.Workflows;
 
    SPWorkflowAssociation workflowAss = yearEnd.WorkflowAssociations[new Guid("369dcef7-b35c-48f1-bf2f-5b9f53d568ee")];
 
    foreach (SPWorkflow itemWorkflow in itemWorkflowCollection)
    {
        if (itemWorkflow.ParentAssociation.Id == workflowAss.Id && (itemWorkflow.InternalState & SPWorkflowState.Running) == SPWorkflowState.Running)
        {
            SPWorkflowManager.CancelWorkflow(itemWorkflow);
            site.WorkflowManager.StartWorkflow(item, workflowAss, workflowAss.AssociationData);
            break;
        }
    }
}

For completeness, this is how I set the hidden field on load that stores the original Date Received value.

// set date received to see if it changes
 dateReceived.Value = Convert.ToDateTime(yearEndItem["Date Received"]).ToShortDateString();

Thanks Tony for the original post that helped me build out the logic above:

http://www.tonytestasworld.com/post/Howto-Start-a-Sharepoint-Workflow-Programmatically.aspx

,

10 Responses to “SharePoint Designer Workflow Pause Until Date Change”

  1. rajiv September 19, 2012 at 4:30 pm #

    I used the Pause Until Date in an OOTB workflow for this, how do i append this to my workflow?

  2. shereen October 19, 2012 at 12:53 pm #

    Hi Rajiv,

    I’m not sure I understand the question. Is the Pause Until Date not working?

  3. SuronoB February 13, 2013 at 10:15 pm #

    Is there any impact to the server performance if I run, say 1000 Paused workflow items each for some 30 lists ? If yes, any better solution ?

    Alerting to specific user is custom in business.

  4. HarryT April 25, 2013 at 6:48 am #

    Hi there,

    I’d like to ask, is it possible to solve this Workflow not saving any changes before Pause Date issue without the use of Visual Studio? I’m a Power User and I do not have access to use Visual Studio on my company

    Harry

  5. shereen April 26, 2013 at 9:08 am #

    Hi Harry,

    Not that I know of; if the date changes, the workflow isn’t notified of it, and will still continue to run against the old date.

  6. Neeraj May 5, 2013 at 5:14 pm #

    Hi Harry,

    I have tackled similar scenario in Nintex workflows by creating a new workflow that runs on item modification and checks if the Pause date input parameter has changed. If the parameter has been modified, my workflow cancels the already running workflow and starts a new instance of the original workflow. When the new instance is kicked off the new pause date parameter is used…..not sure if you can do that in SharePoint OOB workflows though…..

  7. baranee June 26, 2013 at 9:00 pm #

    Hi Shereen,
    Kindly provide full sample code for the Workflow Pause Until Date Change used in Visual studio

  8. shereen June 27, 2013 at 3:29 pm #

    Hi Baranee,

    I will update that this weekend for you.

  9. baranee July 17, 2013 at 7:33 am #

    Hi Shereen,
    Please provide full sample code for the Workflow Pause Until Date Change used in Visual studio 2010

  10. Sameer Vyas November 5, 2014 at 7:06 pm #

    At the start of the workflow, create a variable called Original Date Received and set it to equal Date Received. Make the pause until activity the last part of a stage called “Set Reminder and Pause”. Then in the transition to stage section of “Set Reminder and Pause” stage, put in some conditions like as follows.

    If Date Received equals Original Date Received, then send to a stage called “Email Reminder”, which has the activity to email the user. If the dates do NOT equal, you know someone changed the date, so you can transition back “Set Reminder and Pause” which will reset the Original Date Received variable and pause until the new reminder date.

Leave a Reply