locked
Approval workflow caught in infinite loop.

    Question

  • I'm trying to setup an approval workflow for new and edited items.  I'm using the Announcements list, Contacts list, and Links list.  The lists are set to require content approval.

    I created an approval workflow that is set to start when a new item is created and when an item is edited.  I then tell the workflow to update the approval status when the workflow completes.

    Now when I create a new item or edit an existing item the workflow kicks off as expected.  However when I approve the workflow the workflow completes and then starts a new workflow.  It would seem that updating the approval status is causing the workflow to activate again. 

    I have workflows setup on a Document list and the Pages list that are configured exactly the same way without this infinite loop problem. 

    Does anyone have any suggestions?

     

    Thursday, March 15, 2007 5:36 PM

Answers

  • Okay...so I had this problem too!  and in a production environment! ....and yes it seems to be a bug in the out-the-box approval workflow provided with MOSS2007. 

     

    Good news though! after 2 days (and nights) of blood and sweat I managed to get a solution!!  Unfortunately the out-the-box solution is not the answer...I had to create my own custom workflow.  Don't be afraid to do this yourself...there are loads of resources out on the net to help you do this, try googling for Nick Swan or Rob Shelton's tutorials, both are very good...and if you have the Microsoft MOSS2007 SDK installed there are samples there to get you going. 

     

    I managed to pinpoint the problem down to when the workflow sets the list/doc library moderation status (Approved Status) from pending to Approved, quote simply the list attached to the workflow was re-triggering the workflow as it was set to fire on update as well as create.  So that understood, I went about looking for a way of letting the workflow set the moderation status without firing the workflow again.  I looked at using item.systemupdate instead of item.update, apparently this updates the list without updating the list modified datetime and does not trigger the update workflow but I could not get that to work at all... so I came up with another solution.  The list has an event receiver which will basically fire the workflow, to make sure this does not happen while we update the status, we simply turn off the receiver on the list.

     

    I did this by creating my own class Events which inherits SPItemEventReceiver, I make the private methods DisableEventFiring() and EnableEventFiring() accessible to my code my exposing them as public members like this:

     

    'add this class to your workflow

     

    Code Snippet

     

    Public Class Events

    Inherits SPItemEventReceiver

     

    Public Sub DisableEvents()

    Me.DisableEventFiring()

    End Sub

     

    Public Sub EnableEvents()

    Me.EnableEventFiring()

    End Sub

     

    End Class

     

     

     

    Then in the complete task workflow code-behind, you will want to update the list to and set the Approval Status to 'Approved'.  Actually this is a special property on the list called moderationinformation and is set with an enum which can be 'Pending' or 'Approved', etc.  Just before you call the item.update to save persist the change on the list, call oEvents.DisableEvents(). This will turn off the Event Receiver in this instance and will not fire the workflow again when the item is being update.  Then we turn the Event Receiver back on again by calling oEvents.EnableEvents().

     

    'add this code to the completeTask method in your workflow

     

    Code Snippet

     

    Private Sub completeTask1_MethodInvoking(ByVal sender As Object, ByVal e As EventArgs)

     

    if _ApprovalTaskOutcome = "Approved" then

     

    Dim oEvents As Events = New Events

     

    If Me.workflowProperties.Item.ParentList.EnableModeration = True Then

    Dim moderationInformation As SPModerationInformation = e.workflowProperties.Item.ModerationInformation

    If moderationInformation.Status <> SPModerationStatusType.Approved Then

    moderationInformation.Status = SPModerationStatusType.Approved

    oEvents.DisableEvents()

    Me.workflowProperties.Item.Update()

    oEvents.EnableEvents()

    End If

    End If

       

    End If

     

    End Sub

     

    This fixed the infinite loop issue!  Fortunately for us, we were looking to create a custom workflow anyway so this was two birds with one stone for us.  I hope this helps anyone out there who had got to the stage of almost giving up and waiting for a patch for this! 

     

    oh, and if anyone gets item.systemupdate to work for them please let me know how as it did not work for me.

     

    Duncan

    • Proposed as answer by Omar Damiani Tuesday, February 17, 2009 2:54 PM
    • Marked as answer by Mike Walsh FIN Wednesday, February 18, 2009 5:45 AM
    Thursday, April 3, 2008 8:50 PM

All replies

  • Patrick,

     

    I've just experienced the same issue. 

     

    Did you manage to resolve the problem? 

     

    Regards,

    James

    • Proposed as answer by Tim Carper Friday, April 10, 2009 1:00 PM
    Wednesday, March 28, 2007 12:56 PM
  • Are you updating the status via the callexternalmethod activity?  In general, you shouldn't directly update list items directly from a code activity.

    If you already are, then try putting the entire workflow into a branch of an if/else statement with a condition that will follow an emtpy branch on the if/else activity unless the item's status is a valid status for the workflow.
    Sunday, April 1, 2007 4:42 AM
  • Hi,

     

    I'm using the out of the box Approval workflow and not a custom workflow created in VS or using SPD.

     

    Our customer is keen to keep to an implementation that only involves customisation and configuration but not bespoke development.

     

    Regards,

    James

    Monday, April 2, 2007 12:20 PM
  • James,

     

    I've still not managed to figure this out.  I am also using the OOTB Approval workflow.

     

    Have you had any luck?

     

    Thanks,

     

    Patrick

    Tuesday, April 17, 2007 1:47 PM
  • Hi Patrick,

     

    No I didn't manage to get this to work.

     

    I've not had time yet but I intend to raise a support call with MS.

     

    Regards,

    James

    Monday, April 23, 2007 9:31 AM
  • We have the same problem here ..... Allready found a solution ?

    Marcel
    Thursday, May 3, 2007 6:08 AM
  • I was having a similar problem with a custom list.

     

    What I have found (and I'm not sure if it is the same issue as yours) is that it seems you cannot use both the "Approval" workflow and also enable Content Approval at the same time.  It's an either-or thing.  They seem to conflict with each other.

     

    It kind of sucks because then I have to deal with filtering out unapproved items in my views when using workflow, where if I used Content Approval, Sharepoint would filter out draft items if the user did not have permission to approve them.

     

     

    Thursday, May 3, 2007 1:41 PM
  • Thanks for all the posts on this subject, at least confirming that I am not delusional.

     

    This is what I have found out so far:

    • The second workflow is starting because the workflow is set to begin on item creation and item edit, and because the workflow is set to update the approval status of the item.  So when the workflow updates the Approval Status field, this is seen as a change to the item and kicks of the new workflow (that's stupid)
    • The reason that my Documents, Images, and Pages workflows don't exhibit the same issue is because they are set to begin when I publish a major version.
    • The Link, Contact, News lists don't support major/minor versions so this setting is disabled on those workflows. (so I'm hosed there)
    • if I disable the content approval requirement and only use the workflow then I have to do all the filtering of the draft items (I really don't want to deal with that)

    I've been trying to work with Microsoft on this issue through their partner site.  If I get any resolution to this issue I will post it here.

    Friday, May 18, 2007 8:29 PM
  • Got confirmation that this is indeed a bug with WSS 3.0 and MOSS '07.  No work arounds were offered by microsoft other than what has already been posted here.  They say the product team is aware of the bug and it is on the schedule to be fixed.  Not sure if they'll release a hotfix or if we'll have to wait until SP1.
    Tuesday, May 22, 2007 12:52 PM
  • I'm also experiencing this undesired behavior.

    Did you manage to get more info on this issue?

    Thanks.
    Tuesday, May 22, 2007 12:55 PM
  • Thanks for the update Patrick.

    I'm no developer, but can anyone out there tell me how hard would it be to create a custom hotfix to this solution?
    Tuesday, May 22, 2007 1:01 PM
  • I'm also using the OOTB workflow, and experiencing the same issue. Looks like we cannot use the Content Approval and Approval workflow together. Hope MS can post the fix quickly as this is a cool feature without this booboo.

    RBO

    Thursday, May 24, 2007 1:53 AM
  • Thanks for the update Patrick.

     

    James

    Tuesday, June 5, 2007 8:45 AM
  • Hello,

    I have the same issue with a document library. When I set the approval status on a item to approved or rejected, the workflow starts again. Did you found any solution in the meantime?

    best regards,

    Sarge
    Wednesday, September 12, 2007 2:39 PM
  •  

    Hi,

    I need help.....

    I am want Custom Approvel and Reject work flow in WSS Using VSS.

     

     

    Saturday, October 13, 2007 6:06 AM
  • Same here. Same problem. I published the workflow and had somebody test it. He called me back and cried for help. He mailbox was receiving hundreds of emails. A change in the sharepoint approval status triggers a change event which is not logical.

     

    Any updates on a solution for this problem?

     

    Kind regards,

    Dominique

    Tuesday, November 6, 2007 8:37 AM
  • Okay...so I had this problem too!  and in a production environment! ....and yes it seems to be a bug in the out-the-box approval workflow provided with MOSS2007. 

     

    Good news though! after 2 days (and nights) of blood and sweat I managed to get a solution!!  Unfortunately the out-the-box solution is not the answer...I had to create my own custom workflow.  Don't be afraid to do this yourself...there are loads of resources out on the net to help you do this, try googling for Nick Swan or Rob Shelton's tutorials, both are very good...and if you have the Microsoft MOSS2007 SDK installed there are samples there to get you going. 

     

    I managed to pinpoint the problem down to when the workflow sets the list/doc library moderation status (Approved Status) from pending to Approved, quote simply the list attached to the workflow was re-triggering the workflow as it was set to fire on update as well as create.  So that understood, I went about looking for a way of letting the workflow set the moderation status without firing the workflow again.  I looked at using item.systemupdate instead of item.update, apparently this updates the list without updating the list modified datetime and does not trigger the update workflow but I could not get that to work at all... so I came up with another solution.  The list has an event receiver which will basically fire the workflow, to make sure this does not happen while we update the status, we simply turn off the receiver on the list.

     

    I did this by creating my own class Events which inherits SPItemEventReceiver, I make the private methods DisableEventFiring() and EnableEventFiring() accessible to my code my exposing them as public members like this:

     

    'add this class to your workflow

     

    Code Snippet

     

    Public Class Events

    Inherits SPItemEventReceiver

     

    Public Sub DisableEvents()

    Me.DisableEventFiring()

    End Sub

     

    Public Sub EnableEvents()

    Me.EnableEventFiring()

    End Sub

     

    End Class

     

     

     

    Then in the complete task workflow code-behind, you will want to update the list to and set the Approval Status to 'Approved'.  Actually this is a special property on the list called moderationinformation and is set with an enum which can be 'Pending' or 'Approved', etc.  Just before you call the item.update to save persist the change on the list, call oEvents.DisableEvents(). This will turn off the Event Receiver in this instance and will not fire the workflow again when the item is being update.  Then we turn the Event Receiver back on again by calling oEvents.EnableEvents().

     

    'add this code to the completeTask method in your workflow

     

    Code Snippet

     

    Private Sub completeTask1_MethodInvoking(ByVal sender As Object, ByVal e As EventArgs)

     

    if _ApprovalTaskOutcome = "Approved" then

     

    Dim oEvents As Events = New Events

     

    If Me.workflowProperties.Item.ParentList.EnableModeration = True Then

    Dim moderationInformation As SPModerationInformation = e.workflowProperties.Item.ModerationInformation

    If moderationInformation.Status <> SPModerationStatusType.Approved Then

    moderationInformation.Status = SPModerationStatusType.Approved

    oEvents.DisableEvents()

    Me.workflowProperties.Item.Update()

    oEvents.EnableEvents()

    End If

    End If

       

    End If

     

    End Sub

     

    This fixed the infinite loop issue!  Fortunately for us, we were looking to create a custom workflow anyway so this was two birds with one stone for us.  I hope this helps anyone out there who had got to the stage of almost giving up and waiting for a patch for this! 

     

    oh, and if anyone gets item.systemupdate to work for them please let me know how as it did not work for me.

     

    Duncan

    • Proposed as answer by Omar Damiani Tuesday, February 17, 2009 2:54 PM
    • Marked as answer by Mike Walsh FIN Wednesday, February 18, 2009 5:45 AM
    Thursday, April 3, 2008 8:50 PM
  • I remember stumbling on this issue about a year ago. I expected it to be fixed in SP1. But today I encountered this bug again on a SP1 installation. So I guess it hasn't been fixed yet. Has there ever been an official statement by Microsoft about this issue. I think it is a very serious issue, so I would expect a hotfix...

    Monday, June 16, 2008 11:13 AM
  • I'm seeing the same thing.  Very peculiar.  And very weak on the part of MS.  This should be 101...

     

    Friday, June 20, 2008 8:46 PM
  •  Scott Widener wrote:
    I'm seeing the same thing.  Very peculiar.  And very weak on the part of MS.  This should be 101...

     

     

    Sad this is not in SP1, I wonder if an MVP can give us any insight?

     

    Duncan

    Friday, June 20, 2008 9:37 PM
  • This is great! Well now atleast I know that this really can't be done using the Designer Workflow out-of-the-box Actions alone it really needs to be customized. Sadly, we're not allowed to deploy programs to our server so maybe I need to think of another way, using Javascript perhaps can do the trick.

     

    Thanks Duncan for the info.

     

    • Edited by Mike Walsh FIN Monday, April 4, 2011 8:29 AM a bit more of the quote
    Thursday, July 10, 2008 6:54 AM
  • hi Duncan,

    With the same Approval Workflow i came accross other issue.

    My issue is: 
    Workflow is running fine but the tasks from the workflow are getting created after a time delay of 1-3 days.
    Why this is happening?

    Iam having ItemAdded Event Handler. Is there any problem with that?

    Can anyone help me

    or give me a hint what could be the problem.

    Thanks in Advance.

    Regards,
    Sandra.
    Tuesday, July 15, 2008 7:30 AM
  • I've had this issue of endless loops for ages. I've managed to create a simple hack fix for this.

    Pretty much I design my workflows with SharePoint designer and I have a custom collum Action (New;Update;Sent)
    When I want to create a new Item user selects New, Once the workflow action runs I update the Action (Sent)
    then at the beginning of my workflow I have a check that if Action = Sent then Stop Workflow. This does fire workflow 2 times but then it stops!

    This can also be used when replying to a workflow Action(Update;Sent)

    User selects Update and the workflow runs and then set Item Action(Sent). THere is also a condition to stop the workflow from running when the Action(Sent).

    THis has been the simplest solution so far without having to tough code.



    Hope this helps
    • Proposed as answer by SP10 Sunday, April 11, 2010 4:40 AM
    Thursday, October 16, 2008 11:03 PM
  • I came up with a solution that uses a counter check at the beginning of the workflow. It used the Version Numbering of a form and compares to a counter in my workflow. The counter ticks up 1 ever time the workflow cycles. I store the counter value in the form, which essentially would continue to trigger the workflow. But for the workflow to start, if the counter = the version number, the workflow stops and at this point, no updates are made to the form so it does not trigger the workflow again.

    Ive seen similar solutions, but they would only work once and then the workflow would never fire again. I needed a solution that would fire every time the user actually edited the form. The only problem with my is the Verision number is 2X what it sould be since the workflow triggeres again before actually stopping, but this is probably an easy fix.

    Here is the code, to get a better idea. You must make this your first two steps to any workflow you do, and dont forget to put a counter field (number) in your form:

    Step 1:
    Condition: None
    Action: Calculate UI Version divides by 512 (output to Variable1)

    Notes - This must be done because version number is actually calculated in multiples of 512 - i needed it ton only increment by 1 to keep in line with my counter.

    Step 2:
    Condition: If Counter not equals Variable1
    Action: Calculate Variable1 plus 1 (output to Variable2)
                Then set Counter to Variable2

            Else
    Condition: None
    Action: Stop Workflow and log Counter Stop
    Friday, October 24, 2008 2:17 PM
  • I ran into this approval looping issue for the first time today.  We are running MOSS 2007 SP1.  However, I found a very simple way around this loop.  When you setup the approval workflow, be sure NOT to check "Start this workflow when an item is changed".  If you do that, it should avoid the approval/task loop.

    Of course you'll loose the workflow being kicked off if the approved item gets changed, but at least you'll get some functionality OOTB from the approval workflow!

    Tuesday, January 27, 2009 2:36 AM
  • I have just started using MOSS2007 and this "Approval" workflow and got into the same problem. I found this solution from Microsoft. I havent tried it myself yet but will do

    http://support.microsoft.com/default.aspx?scid=kb;en-us;955586

    Share if it helps.

    Thx
    • Proposed as answer by Zaid.Bilal Wednesday, February 18, 2009 5:06 AM
    • Unproposed as answer by Mike Walsh FIN Wednesday, February 18, 2009 5:45 AM
    Wednesday, February 18, 2009 5:04 AM
  • The work-a-round I came up with was to let the workflow trigger on a change, but not to have the workflow update the "Approval Status" for the item in the list.   Then when the approver reviews the change (and he can edit it further if necessary) he sets the "Approved Status" for the item manually to "Approved".  Then, after doing this, he separately also approves the workflow, and at this point the changes are accepted by the workflow and another workflow is not triggered.
    Monday, March 23, 2009 7:54 PM
  • After applying the Hotfix from Microsft nothing change. I had the same behavior.
    But then I tried some thing that resolve the problem.
    I add a step in my work flow (and this is because I update file in parallel),  and add an action to wait 1 minute.

    Let us know if that work for you too.
    Tuesday, April 14, 2009 8:32 PM
  • I applied the hotfix also and it didn't fix the issue.  I am opening up a ticket with Microsoft.
    Wednesday, June 17, 2009 4:40 PM
  • I applied the hotfix also and it didn't fix the issue.  I am opening up a ticket with Microsoft.

    If you get a answer to that, help us, we have the same problem here.
    Wednesday, July 29, 2009 12:19 PM
  • Hi Guyas

    we can play a trick , create a spd wf which will be fired on when approval status equal to 'ur desired status' then copy item to new document library then delete item from current library.

    A suggestion only may be helpfull
    Monday, September 14, 2009 4:53 AM
  • I came across the same situation I was creating SPD 07 workflow. I have tried your trick. I did work but to implement this we actually require service pack 2.  

    Thank you very much

    Sunday, April 11, 2010 4:42 AM