Friday, September 9, 2011

Updating list items without changing the Modified field

In some situations, we want to programmatically update some fields in a list item without users knowing about it. The reasons may be varied; for instance, maybe you are only filling some control fields to record some action performed in a workflow and not editing the "true" metadata of your document/item.

The SharePoint Server API has 2 solutions for this, in our SPListItem object (MSDN quote):
  1. UpdateOverwriteVersion(): updates the current list item without creating another version of the item.
  2. SystemUpdate(): updates the database with changes made to the list item without changing the Modified or Modified By fields.When you call the SystemUpdate method, events are triggered and the modifications are reported in the Change and Audit logs, but alerts are not sent and properties are not demoted into documents.
In my scenario, I used UpdateOverwriteVersion(), since I was actually creating a way to copy discussions between lists and was setting the Author, Created and Editor explicitly. I just needed to avoid having the Modified dates getting messed up, and this method solved it.

From other information I could collect, SystemUpdate() may be very useful to use in custom workflow actions where the Update() would make the workflow call itself recursively.

No comments:

Post a Comment