Geeks With Blogs
Molnar Tibor blog

I recently joined a project which automates different processes from a company using MOSS 2007 with Workflow Foundation and InfoiPath 2007 forms.

We have the following scenario: create a SharePoint task in a deployed workflow with the CreateTask activity, wait for its completion with the OnTaskChanged activity and then delete the task with the DeleteTask activity. We have to control the timeout, so we tried to use in a parallel branch a Delay activity.

In SharePoint 2007, if a workflow has a delay activity in a repeating control, the workflow goes idle and is persisted as designed but it is not awaked always as expected. We run several tests by puttting a one minute delay in an infinite While loop, sometime is working even for few hours but after that the workflow is awaked randomly (might happen that more that 1 hour passes, instead of the set 1 minute, before anything happens).

Beign a Gold Certified partner, we opened an incident at Microsoft, we found out that this is a known issue but right now it is not planned to be solved.

The workaround:

  • create a console application (the timer service) which iterates through a SharePoint web site's list to which the worklow is attached and for every item, for  the attached tasks, calls the SPWorkflowTask.AlterTask method just to trigger an update on the task
  • register this console application in the Windows Scheduling service
  • do not use a Delay activity in a parallel branch, put the OnTaskChanged in a While loop
  • any time the scheduled console app updates the corresponding task, check in the Invoked event handler of OnTaskChanged whether the task was completed or we have a timeout, if non of these happens, loop again, wait for the next update which can come from the scheduled app or the user to whom the task is assigned

The code below is the part of the timer service that iterates all subsites of a site and updates a any SPWorkflowTask attached to any item from a list with a given name. The code references the Microsoft.Office.Servers and Microsoft.SharePoint assemblies. You can change it easily upon your needs.

        using (SPSite site = new SPSite("your site url"))
        {
            ServerContext context =
            ServerContext.GetContext(site);

            SPWebCollection allSites = site.AllWebs;
            SPWorkflowManager SPWFM = site.WorkflowManager;

            foreach (SPWeb subSite in allSites)
            {
                SPListCollection allSiteLists = subSite.Lists;
                foreach (SPList subSiteList in allSiteLists)
                {
                    if (subSiteList.Title == "your list name")
                    {
                        SPQuery query = new SPQuery();
                        query.Query = "";

                        SPListItemCollection listItems = subSiteList.GetItems(query);

                        foreach (SPListItem listItem in listItems)
                        {
                            // active workflows
                            SPWorkflowCollection SPWFCollection = SPWFM.GetItemActiveWorkflows(listItem);

                            foreach (SPWorkflow SPWorkflow in SPWFCollection)
                            {
                                foreach (SPWorkflowTask SPWFTask in SPWorkflow.Tasks)
                                {
                                    Hashtable SPTaskExtendedProperties = SPWorkflowTask.GetExtendedPropertiesAsHashtable((SPListItem)SPWFTask);

                                    logger.Info(string.Format("Updating task with title {0}.", SPWFTask.Title));
                                     try
                                    {
                                        SPWorkflowTask.AlterTask((SPListItem)SPWFTask, SPTaskExtendedProperties, true);
                                    }
                                    catch (Exception exc)
                                    {
                                        logger.Error("Error altering task: ", exc);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }


Posted on Tuesday, October 2, 2007 2:36 AM SharePoint 2007 | Back to top


Comments on this post: Task timeout control in MOSS 2007 Workflow - the workaround for the Delay activity bug

# re: Task timeout control in MOSS 2007 Workflow - the workaround for the Delay activity bug
Requesting Gravatar...
I'm having issues with getting access to the sharepoint sites. It appears to be a rights issue. I'm an admin on the server and a member of the sharepoint admin group and the app is running as me. I get an unauthorized access error.
Left by Charlie on Mar 11, 2008 1:53 AM

# re: Task timeout control in MOSS 2007 Workflow - the workaround for the Delay activity bug
Requesting Gravatar...
Are you getting error in the
using (SPSite site = new SPSite("your site url"))
code line?
Left by Tibor Molnar on Mar 11, 2008 1:57 AM

# re: Task timeout control in MOSS 2007 Workflow - the workaround for the Delay activity bug
Requesting Gravatar...
Hello

Someone could help me and tell me how to do that after some time that the workflow creates a task if this is not accepted or approved the assign to another person.
My WF already created and assigned the task, but as you say 3 days if not accepted, the reallocation?
Help please'm lost, I'm working with new workflows
Left by perla on Jul 10, 2009 6:46 PM

# re: Task timeout control in MOSS 2007 Workflow - the workaround for the Delay activity bug
Requesting Gravatar...
Hi,

Looks like this might be a deployment issue. The Timer Service doesn't pick up the new assembly.

Not sure if it will work for you but please check my blog for a simple solution to my similar issue:

http://www.onlinetechblog.com/blog/index.php/2009/08/sharepoint-workflow-delay-activity-not-firing-vs2008-state-machine-workflow/
Left by Tim Lefler on Aug 14, 2009 2:27 PM

Your comment:
 (will show your gravatar)


Copyright © Molnar Tibor | Powered by: GeeksWithBlogs.net