There is a field in my list called Authority Name and its type is Person. I am writing ItemAdding event receiver where I want to change this fields value.
For e.g. if user is adding Mike in this field then I want to replace it with John. I have tried both SPUser and SPFieldUserValue but getting error in both.
If I try following where myspuser is a SPUser object then I get error
properties.AfterProperties["Authority_x0020_Name"] = myspuser; Error
Invalid data has been used to update the list item. The field you are trying to update may be read only
If I try following where I am trying to conver SPUser to SPFieldUserValue then I get error
SPFieldUserValue myspfielduservalue = new SPFieldUserValue(context.Web, myspuser); Error
Value does not fall within the expected range
Is it not possible to update Person or Group field in ItemAdding event?