One of friend came up with this error while updating a lookup column in a list in SharePoint event handler.
When updating the look up column, we should not assign the value directly. Instead,we need to assign the Id of the lookup value.
I have a lookup column Country which gets the value from another list named “Country”.
If I update the value as
results in the above error : Invalid data has been used to update the list item. The field you are trying to update may be read only.
Here I wrote one helper function which will return the SPLookupFieldValueCollection which can be set to the field.
- Call this method like this
item["Country"] = GetLookFieldIDS(“Australia”, lookupFieldList);
- If the LookupField allows multiple values
item["Country"] = GetLookFieldIDS(“Australia,India”, lookupFieldList);