Wednesday, May 7, 2008

Save Conflict / Recursive call of event handler / Update item in item updating and adding

Microsoft.SharePoint.SPException: Save Conflict
Your changes conflict with those made concurrently by another user.
If you want your changes to be applied, click back in your Web browser, refresh the page, and resubmit your changes.

This post is also solution of
Recursive call of event handler and update item in item updating and adding

Once I was suffering from “Save Conflict” error while updating a List item.
This thing happens when to achieve two of my business requirements.


Scenario 1:
In my scenario I have a workflow attached with the list. While adding or updating item from this list, by default workflow is attached to the list. Now as per my requirement. On workflow activated and on task generated again I want to fill one field in the same list. I got “Save conflict” error while updating that list item from workflow.

Scenario 2:
In one of my list in item handler I’m creating a sub site with the Title of the item. What I want to do is that in item added I want to update the list field. But while updating I’m having this “save conflict” error.

So in both the case what I found was that when we are calling
ListItem.Update();
method, list’s ItemUpdating event fires and again all the procedure go in to the recursive loop.
To solve this problem try one of these code snippets.

1) (useful while updating List/web from outer side of the scoop of that web or site)
web.AllowUnsafeUpdates = true;
ListItem.SystemUpdate(false);
or
ListItem.Update();
web.AllowUnsafeUpdates = false;
//must set AllowUnsafeUpdates to false if we are set it to true.

2) (Usefull in from updating Item from event handler)
Item[FieldName] = FieldValue;
this.DisableEventFiriing();
item.SystemUpdate(false);
or
item.Update();
this.EnableEventFiring();
//must enable event firing if we are disable it


hopefully this post will help you guys for solving your problem.

Cheers.

No comments:




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com