1

Event in question is item added event, and I am updating (systemupdate) same item multiple times.

Behind the scene:

  1. Site is multilingual (English,french,spanish)
  2. List item variation propagation is enabled, so I believe event receiver will fire multiple times once with w3wp process, and twice with owstimer.(Correct me if I am wrong)
  3. Sole purpose of event receiver is to break the role inheritance of list item and reassign some permissions after iterating through site groups.

code:

try
                {
                    this.EventFiringEnabled = false;
                    string siteurl = properties.WebUrl;
                    SPListItem _currentItem = properties.ListItem;
                    int itemid = _currentItem.ID;

                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        using (SPSite site = new SPSite(siteurl))
                        {

                            using (SPWeb web = site.OpenWeb(properties.ListItem.Web.ID))
                            {  
                                if (properties.ListItem.ModerationInformation != null && properties.ListItem.ModerationInformation.Status == SPModerationStatusType.Approved && properties.ListItem.Level == SPFileLevel.Published)
                                {    
                                    web.AllowUnsafeUpdates = true;
                                    SPList myList = web.Lists.TryGetList("listName");
                                    SPListItem item = myList.GetItemById(itemid);

                //fetch some values from item object

                                    foreach (string value in collection)
                                    {
                                        if (!item.HasUniqueRoleAssignments)
                                          {
                    //break item role inheritance
                                            item.SystemUpdate(false)
                                          }

                                       //logic to add permissions to the item 
                                       item.SystemUpdate(false)
                                       // there are n number of permissions so item.systemupdate is called multiple times
                                       //logic to add permissions to the item 
                                       item.SystemUpdate(false)
                                       //logic to add permissions to the item 
                                       item.SystemUpdate(false)
                                       //logic to add permissions to the item 
                                       item.SystemUpdate(false)
                                    }

Event Firing is disabled at the start of event receiver but still sometimes I found it to true at the later stage.

Item I am updating is on the same list on which the event receiver is firing.

I am getting save conflict errors at various item.SystemUpdate()

Please suggest!

1 Answer 1

2

You may need to get a new reference to the item after each update:

// code before first update
item.SystemUpdate(false);
item = myList.GetItemById(itemid); // get new reference

// next bit of logic here...
// ...
item.SystemUpdate(false);
item = myList.GetItemById(itemid);

// etc, etc
1
  • This did fix the issue, just need to perform an additional step i.e restarting sharepoint timer service so that fresh event receiver code execute when called by owstimer process after variation propagation
    – user4205
    Jul 28, 2016 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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