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 LindgrenCommented Aug 8, 2013 at 8:44
-
SystemUpdate() does not disable event firing, though it is "quieter" than Update(). msdn.microsoft.com/en-us/library/ms461526.aspx– lgaudCommented Aug 8, 2013 at 13:34
2 Answers
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,
-
Unless you are developing for SP2007, you should use the EventFiringEnabled property instead of EnableEventFiring()– lgaudCommented Aug 8, 2013 at 13:31
-
Would you like to add reference for what you stating please :) ? Commented Aug 8, 2013 at 13:42
-
1DisableEventFiring() / 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/…– lgaudCommented Aug 8, 2013 at 13:45
If you are using sharepoint 2010 then use this before item updating or list updating
base.EventFiringEnabled = false;
item.Update();
base.EventFiringEnabled = true;