By default SPD 2010 does not allow possible infinite loops to be added to a workflow. Here is the guide how you can do it:
- Open SPD 2010
- Add a new Workflow
- Add new IfElseActivity and fill in the conditions and the actions you want to loop through
- Save the workflow
- Go to Alle Files -> Workflows -> Your workflow name folder and open “your workflow name.xoml” file as xml.
- Locate the lines that look like this:
<IfElseActivity x:Name="ID411"> <IfElseBranchActivity x:Name="ID412"> <IfElseBranchActivity.Condition> <RuleConditionReference ConditionName="__Rule_ID412" /> </IfElseBranchActivity.Condition>
And replace if with something like this:
<WhileActivity x:Name="ID411"> <WhileActivity.Condition> <RuleConditionReference ConditionName="__Rule_ID412" /> </WhileActivity.Condition>
Keep in mind that you have to remove also the ending tag of the IfElseBranchActivity. Keep also in mind that if you have multiple activities in the IfElseActivity taht you have to encapsulate these activities into one single SequenceActivity.
Now you can Publish your workflow back to SharePoint.
One drawback of this approach is that SPD does not support designing of a whileactivity in the worklow designer so you have to change the activities direct in the xoml file or you can replace the whileactivity again with ifelseactivity, do your changes and replace it again.
You have to also modify the web.config of the web app where you want to deploy your workflow because by default is the WhileActivity disabled. Locate following line
<authorizedType Assembly="System.Workflow.Activities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Workflow.*" TypeName="WhileActivity" Authorized="False" />
and set the “Authorized” attribute to True.
Tags: SharePoint, SharePoint 2010, SharePoint Designer, Workflows
November 1, 2010 at 6:09 pm |
[…] Creating Loops in SharePoint Designer 2010 Workflows […]
November 1, 2010 at 6:13 pm |
[…] Creating Loops in SharePoint Designer 2010 Workflows […]
July 11, 2012 at 3:32 pm |
Hi,
I did your tutorial and when I publish the workflow get this error: “(0, 0) Activity ‘ID4’ validation failed: WhileActivity should have one child activity.)”.
Can you help?
Regards,
Carlos
July 12, 2012 at 1:06 pm |
Hi Carlos.
I think that you have multiple activities under the whileactivity. You have to encapsulate these activities with one SequenceActivity
Regards
Vojta
July 16, 2012 at 10:04 am |
Hi Vojtan,
i do what you say to me, but when i open again th workflow in SP Designer 2010 doesn´t appear anything. This is normal?
Regards,
Carlos
August 23, 2012 at 5:01 pm |
Yes this is normal. The SharePoint Designer 2010 is not able to display the while activity. Sorry for the late responce.
August 23, 2012 at 2:46 pm |
Hi,
Once I make changes to the code within the workflow, I am no longer presented with the option to Publish. Is there another way i can go about doing this?
Thank you!
Erica
August 23, 2012 at 4:59 pm |
Hi. Are you sure that the xml syntax is correct? Can you validate the workflow syntax? I did not have this problem.
August 23, 2012 at 6:48 pm
Vojtan,
Per your request:
When I go to the workflow settings where you can edit using SP Designer controls, it says that SP Designer is unable to display the item, which I understand. It’s just that this is where I go to publish the workflow, that option is not available. Is there another way i can go about doing this?
Thank you in advance for any help you can provide with this.
Erica
August 23, 2012 at 6:51 pm
Syntax did not post in previous posting:
August 24, 2012 at 9:04 am |
As far as I can remember the sharepoint designe does not display any messages when you add the while activity. It just does not display the activity.
September 26, 2012 at 2:16 pm |
Hi Vojtan,
Do you have a small example? Forinstance: do you need a closing tag?
And the sequence activaty where do you place the WhileActivity withing?
or
Thanks in advance.
September 27, 2012 at 3:36 pm |
Yes you need a closing tag. Locate the /IfElseActivity tag and replace it with /WhileActivity tag. The sequence activity remains within the WhileActivity and /WhileActivity tags. HTH
August 13, 2014 at 11:00 pm |
Works beautifully . . . Thanks mate!
October 28, 2014 at 12:05 pm |
Update… After editing the .xoml file and placing “The sequence activity within the WhileActivity and /WhileActivity tags.” as mentioned… no errors in publishing.. but the workflow itself fails on start.
Thanks
December 14, 2015 at 2:17 pm |
Did you ever figure out how to correct your “Failed on Start” problem? I am having the same issue.
Thanks