1

I am using a item updated event on one list to add an item into some other list, but it is adding the same item multiple times in the list

  • Without code it is hard to see where you go wrong, but one common problem is using .Update() instead of .SystemUpdate(). Doing an .Update() will again trigger your event receiver. EventFiringEnabled = false is another life saver – Robert Lindgren Aug 8 '13 at 8:44
  • SystemUpdate() does not disable event firing, though it is "quieter" than Update(). msdn.microsoft.com/en-us/library/ms461526.aspx – lgaud Aug 8 '13 at 13:34
1

As Robert said it's hard to figure out what's wrong with your event receiver until we see your code but most commonly you can solve this problem by using this.DisableEventFiring(); event. Check this example code,

class myEventReceiverClass: SPItemEventReceiver
{
    public override void ItemUpdated(SPItemEventProperties properties)
    {
        try
        {
            this.DisableEventFiring();

            // Only Execute if item hasn't been changed in edit form
            if (!properties.Versionless)
                ExecuteMyCode(properties);
        }
        finally
        {
            this.EnableEventFiring();
        }
    }
}

Also sometimes developer use ItemAdded and then ItemUpdated at same time as if you add a item to list it trigger's item added when item is added and item updated when we update item's properties in Edit form.

For more details check this link,

Preventing Multiple Events

| improve this answer | |
  • Unless you are developing for SP2007, you should use the EventFiringEnabled property instead of EnableEventFiring() – lgaud Aug 8 '13 at 13:31
  • Would you like to add reference for what you stating please :) ? – Muhammad Raja Aug 8 '13 at 13:42
  • 1
    DisableEventFiring() / EnableEvnetFiring() are obsolete as of SP2010, in favor of the EventFiringEnabled property. The property allows for more control in some situations where you need to know the original state. msdn.microsoft.com/en-us/library/… – lgaud Aug 8 '13 at 13:45
0

If you are using sharepoint 2010 then use this before item updating or list updating

base.EventFiringEnabled = false;
item.Update();
base.EventFiringEnabled = true;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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