Search This Blog

Monday, September 30, 2013

What is the difference between Item.Update() and Item.System.update()?

Generally when we try to add/edit a SPListItem using SharePoint Object Model? Yes I know it! Almost everybody have common answer to this (which is similar to what is provided below).
       SPListItem item = SPList.Item.Add();
       Item[“Col1”] = “Value for Col1”;
       Item[“Col2”] = “Value for Col2”;
       Item.update();
The last line in the code above "item.Update()" does the final task of updating all the assigned value for that specific item within the SPList.
But is this the only way to update an item? No, we can also update the same item using item.SystemUpdate();

Then what is the difference between the two?

With item.update(), we update the changes that are made to the list item. Is that all what it does? No, internally it also updates the “ModifiedBy” and “ModifiedOn” fields as per the current logged in user and current server time. Optionally it also updates the version of the item if the versioning option is turned on for that specific list.
So, at any point if we wish not to update these extra things I.e. the “ModifiedOn” , “ModifiedBy” and the “Item Version”, then the solution for it is to use item.SystemUpdate() instead of item.Update().This will help you in updating only those fields which are specified within your code blocks.

 Conclusion: item. Update () will update the changes that are made to the list item as well as “ModifiedBy”, “ModifiedOn” and “ItemVersion” If Version is enabled.

item.SystemUpdate() will updates the changes that are made to the list item only, it will not update the “ModifiedBy”, “ModifiedOn” and “ItemVersion”.


No comments:

Post a Comment