Nick Grattan's Blog

About Microsoft SharePoint, .NET, Natural Language Processing and Machine Learning

Creating While Loops in SharePoint Designer Workflows using Stateful Workflows

with 14 comments

For an update on this topic please see this blog entry: https://nickgrattan.wordpress.com/2010/12/14/while-loops-in-sharepoint-designer-workflows/

Amongst several significant limitations with SharePoint Designer workflows, perhaps the most important is the lack of looping. Therefore, expressing processes like “while not approved, rework” becomes difficult.

We have published a paper that describes how to implement while loops by emulating stateful workflows in Microsoft SharePoint Designer. You can download the paper here (PDF, Oct 2009). The technique uses our “Restart this workflow” custom action, which is part of our “Custom Activity Pack” which can be downloaded here for free.

Update: 10-Nov-2013. Source code and WSP now available in GitHub: https://github.com/NickGrattan/NGCCustomActivities.git

Written by Nick Grattan

October 6, 2009 at 10:00 am

14 Responses

Subscribe to comments with RSS.

  1. I was trying to install, went through the steps, I have MOSS 2007 sp2 on a windows server 2003 machine.

    I believe I did everything as you detailed, but I can see the Custom activities, but when I try and select one, it doesn’t do anything. I don’t see a new entry for the selected activity. Acts as though I haven’t selected anything. Any ideas?

    Brian

    October 16, 2009 at 5:09 pm

  2. Brian,

    This behaviour normally implies that the assembly and the ACTIONS file have been correctly installed but that the authorized type element in web.config is wrong. The most likely cause is that you’ve added it to the wrong web.config.

    Check that the web.config you edited is for the web application you are creating the workflow in. To do this, match the port number in the URL you use in SPD to connect to the site with the folder name under inetpub where you edited the web.config.

    Hope this helps, regards, Nick.

    Nick Grattan

    October 16, 2009 at 6:07 pm

    • woohoo! Ok, its working now. Thanks a bunch.

      Brian

      October 16, 2009 at 6:26 pm

      • I tried out your restart workflow and I notice that it wipes out the existing workflow and all of the tasks associated with it previously and starts a new one. Is this the way it has to do it?

        I guess my main issue is that when a workflow for list A updates a field in list B, and there is a workflow that is set to restart on change to list B, it sometimes restarts the workflow and sometimes doesn’t. Its driving me nuts. Is that a bug?

        Brian

        October 16, 2009 at 10:43 pm

      • “Restart This Workflow” will cancel the existing workflow and restart it. A side effect of this is that the task list for the cancelled workflow is removed by SharePoint. However, the completed tasks will remain in the “Tasks” list.

        I don’t understand the statement “there is a workflow that is set to restart on change to list B”. Can you explain what you are trying to do here. Thanks, Nick.

        Nick Grattan

        October 19, 2009 at 3:01 pm

  3. I noticed that you don’t have any documentation on how to use the While True Call Workflow activity? How do I add a formula to test for ending the While?

    Thanks,
    Brian

    Brian

    October 16, 2009 at 11:49 pm

    • Woops, Brian, thanks for pointing that out. “While True Call Workflow” activity was not meant to make it into this release. It will be in the next release, and will allow a workflow to be called while a “Yes No” column in the list remains true. Nick.

      Nick Grattan

      October 19, 2009 at 3:03 pm

      • Just wondering. When do you think you might be releasing that While True activity. I could really use something like that.

        Brian

        October 20, 2009 at 11:52 pm

  4. Oh, I see. Well, I’m looking forward to getting your update to the While True Call Workflow activity.

    Clarifying that statement, For the workflow for list B, I checked the box that says “automatically start this workflow whenever an item is changed” as well as start workflow when new item is created. I notice that when I update a field in list B, sometimes the workflow will start again at the beginning and then sometimes it will just complete, and not restart. It is an intermittent error. Reading through your posts and others, I’m not sure if this was disallowed with SP2 or not.

    Brian

    October 19, 2009 at 3:50 pm

    • Brian, I think you have a race condition here – depends on which event is detected first. I would avoid using “automatically start this workflow whenever an item is changed”. If you using “Restart This Workflow” and using a state model in your workflow you should not need to set this option. The “Wait for field change in current item” might be a better option. Regards, Nick.

      Nick Grattan

      October 20, 2009 at 2:22 pm

  5. […] a comment » Here’s some additional information to this post about this […]

  6. […] 25 Nov 2009: See this post for how while loops can be simulated using stateful workflows with Microsoft SharePoint […]

  7. Anyone know if this Custom Activity Pack is still available? Link above doesn’t work anymore and I need a custom activity to start another workflow from an existing workflow in WSS 3.0 (yeah it’s old…my company won’t spring for a new version yet).

    I could REALLY use this pack if anyone can point me in the right direction!

    John Mankos

    November 6, 2013 at 7:59 pm


Leave a comment