locked
Disable Event Firing for item.Update() in workflow RRS feed

  • Question

  • Hi,

     

    I’m having  an issue with the item.Update() method. When I update an item on my SharePoint website, a workflow gets started. In the onWorkflowActivated1_Invoked event, I’m requiring to update the item again. This is firing the onWorkflowActivated1_Invoked event again and things end up in an infinite loop. Below is my partial code:

     

    Code Snippet

    private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)

          {

                try

                {

                    SPListItem item = workflowProperties.Item;

                    SPUser spUser = GetSPUser();

                    item["Assigned To"] = spUser;

                    item.Update();

                }

                catch (Exception ex)

                {

                    SendEmail(ex);

                }

          }

     

     

    I tried item.SystemUpdate(), but MSDN documentation says SystemUpdate() also fires events and I’ve confirmed this. I’ve seen some code with method calls like DisableEventFiring() and EnableEventFiring() but I’m not sure how to include them in my code. Please help.

     

    Thanks

    Arun

    • Moved by Mike Walsh FIN Monday, July 6, 2009 8:06 AM wf q (From:SharePoint - Development and Programming)
    Wednesday, March 12, 2008 4:55 PM

Answers

  • DisableEventFiring and EnableEventFiring are used in case of list event handlers only, where in you can disable the recursive calls to event handler. I am not sure if its applicable in workflows.

    Madhur
    Wednesday, March 12, 2008 6:30 PM

All replies

  • DisableEventFiring and EnableEventFiring are used in case of list event handlers only, where in you can disable the recursive calls to event handler. I am not sure if its applicable in workflows.

    Madhur
    Wednesday, March 12, 2008 6:30 PM
  • Thanks for the update Madhur. How else do you think I could do this?

     

    Now, I don't mind overriding the list event handler for ItemUpdated event and including my implementation in that method, but please let me know if this is possible and if possible, give me some code hints for the same.

     

    Thanks

    Arun
    Wednesday, March 12, 2008 6:43 PM
  • You can use it like this, in your event handler code.

    this.disableeventfiring()

    //your update code..

    //this.enableeventfiring()

    Or as alternative, make your workflow conditional, i.e. it can be called again and again without having any effect.
    It should do what its supposed to do based on presence of some specific parameter.
    Wednesday, March 12, 2008 6:49 PM
  • I have exactly the same need i.e. I need to update an Item in a List from a Workflow such that it does not fire Item Updating/Updated events in that List Item.
    SystemUpdate (from SP1 I believe) fires these events now. What is the solutions to this? I have to do this from workflow only.


    Please advise.

    Thanks,
    Mo
    Monday, July 6, 2009 7:21 AM
  • Moving the whole thread to the workflow forum.
    WSS FAQ sites: http://wssv2faq.mindsharp.com and http://wssv3faq.mindsharp.com
    Total list of WSS 3.0 / MOSS 2007 Books (including foreign language) http://wssv3faq.mindsharp.com/Lists/v3%20WSS%20FAQ/V%20Books.aspx
    Monday, July 6, 2009 8:05 AM
  • Use item.SystemUpdate(false);   //writes directly the data to the database, without invoking update event
    Tuesday, September 15, 2009 5:16 PM
  • Here is the solution which i got from this Link. You need to create a separate class in your workflow project and call it's enable and disable event firing functions as shown below: This solution worked perfectly for me.
    class HandleEventFiring : SPItemEventReceiver
    {
    public void AccDisableEventFiring()
    {
    this.DisableEventFiring();
    }

    public void AccEnableEventFiring()
    {
    this.EnableEventFiring();
    }
    }
    • Proposed as answer by Rizwan.Ansari Tuesday, January 12, 2010 10:10 AM
    Tuesday, January 12, 2010 10:05 AM