Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have two sharepoint lists on which I have two custom workflows running automatically on Item added / updated. Now when workflow from list 1 is updating item on list 2, then item added event of list 2 triggers the workflow on it and then workflow 2 from list 2 starts to copy the item from list 2 to list 1 and this cycle continues...

How to stop this please guide .

Thanks

share|improve this question

2 Answers 2

You can implement this method

public static void SystemUpdate(this SPListItem item, bool incrementListItemVersion, bool doNotFireEvents)
{
    SPItemEventReceiverHandling rh = new SPItemEventReceiverHandling();
    if (doNotFireEvents)
    {
        try
        {
            rh.DisableEventFiring();
            item.SystemUpdate(incrementListItemVersion);
        }
        finally
        {
            rh.EnableEventFiring();
        }
    }
    else
    {
        item.SystemUpdate(incrementListItemVersion);
    }
}

internal class SPItemEventReceiverHandling : SPItemEventReceiver
{
    public new void DisableEventFiring()
    {
        base.DisableEventFiring();
    }

    public new void EnableEventFiring()
    {
        base.EnableEventFiring();
    }
}

You should use this method to update item in your workflow. In this case the event does not fired. So the workflow does not started )

share|improve this answer
    
If I understand the problem right the workflow is the cause of the problem - not the event receiver. –  Alex Boev Feb 21 '12 at 9:13
    
the problem is in code that invokes item.Update() on item which is processed by workflow. If you invoke this method the trigger for workflow that is configured to start on item update are executed. –  Alexander Feb 21 '12 at 9:16
    
Do I understand right that your code may be used outside event reciever ItemAdded etc. event and will work in the same DisableEventFiring manner as inside event receiver? –  Alex Boev Feb 21 '12 at 9:33
    
I have to mention here that to update the item I am using Client Object Model of SharePoint 2010. –  RHM Feb 21 '12 at 10:01
    
@Alexander: I've examined your example for disable event firing outside an event receiver and can agree now that it must be the simplest way to resolve discussed issue. I've upvoted your answer. :) –  Alex Boev Feb 21 '12 at 10:18

One of the ways to prevent it is to create a special boolean column and to use it as flag. You can set it from the workflow and then check it in event receiver - if it's true you need to set it to false in event receiver and return with no further action. It's no so elegant but it works. :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.