Invalid data has been used to update the list item

I thought over the next couple of weeks I can share some development\coding topics on Sharepoint 2010. Starting with:

“Invalid data has been used to update the list item. The field you are trying to update may be read only”

This error is usually occurs when updating or creating a new list item that contains a person\group field. As per normal with Sharepoint 2010 (and Microsoft for that matter) the error description has nothing to do with the actual problem (anyone remember “~ of ~ failed”).

The error is caused because of the method we use to update the person field, in my case it was:

Item[“Assignee”] = Environment.Username;

The correct way to do this and any use of the SPUser class would be:

SPUser user = web.EnsureUser(Environment.Username);

Item[“Assignee”] = user;

 

The EnsureUser method does some internal “magic” and make person field updates a lot less prone to error.

1 thought on “Invalid data has been used to update the list item

Leave a Reply

Your email address will not be published. Required fields are marked *