Hi.
I am getting below error while adding value to look-up field.
Invalid data has been used to update the list item. The field you are trying to update may be read only.
I have tried many forums ans post but didn't come to know what's the root cause of issue. I am also posting Code for creating and adding lookup field.
CAML to create lookup field (It works Fine)
string lkproductNumber = "<Field Type='Lookup' DisplayName='Product Number' StaticName='ProductNumber' ReadOnly='FALSE' List='" + pNewMaster.Id + "' ShowField='Product_x0020_Number' />";
Code to insert value to lookup field
ClientContext client = new ClientContext(SiteUrl); client.Load(client.Web); client.Credentials = new NetworkCredential(this.UserName, this.Password, this.Domain); // Lookup Lists List pmList = client.Web.Lists.GetByTitle("Product_Master"); //List Conatining Lookup Columns List piList = client.Web.Lists.GetByTitle("Product_Inventory"); client.Load(piList); query.ViewXml = "<View/>"; ListItemCollection collection = pmList.GetItems(query); client.Load(collection); client.ExecuteQuery(); int prodid=0; foreach (ListItem item in collection) { if (Convert.ToString(item["Product_x0020_Number"]) == ProductNumber) { prodid = Convert.ToInt32(item["ID"]); } } ListItem piItem = piList.AddItem(new ListItemCreationInformation()); piItem["Product_x0020_Number"] = new FieldLookupValue() { LookupId = prodid }; piItem.Update(); client.ExecuteQuery();
Exception Detail
Microsoft.SharePoint.Client.ServerException was caught Message=Invalid data has been used to update the list item. The field you are trying to update may be read only. Source=Microsoft.SharePoint.Client.Runtime ServerErrorCode=-2147352571 ServerErrorTypeName=Microsoft.SharePoint.SPException ServerStackTrace="" StackTrace: at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream) at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse() at WebServiceProviders.ClientServices.NewProductInventory() in Z:\.............ClientServices.cs:line 889 InnerException:
Quick response is highly appreciated.
Thanks
Mehar
- Edited by Mehar Muhammad Afzal Hamid Tuesday, November 27, 2012 3:17 PM