Update column having external data as data type using CSOM
-
23-12-2020 - |
Question
I have a list which contains a column having data type as "External Data". I want to update that particular column using CSOM. I have tried below code:
ClientContext clientContext = new ClientContext(SharePointSiteUrl))
Web web = clientContext.Web;
clientContext.Load(web);
List splist = web.Lists.GetByTitle(SharePointListName);
ListItem oListItem = splist.GetItemById(ID);
oListItem["ExternalDataColumn"] = "Current";
oListItem.Update();
clientContext.ExecuteQuery();
Here ExternalDataColumn has "External Data" data type. The Problem is where that field is empty I cannot able to set the new value. But where it contains the value and if I change that value, then it updates successfully.
I am facing the Problem with the blank values.
Any help would be appreciated.
La solution
Use the below code to update.
ClientContext clientContext = new ClientContext(SharePointSiteUrl))
Web web = clientContext.Web;
clientContext.Load(web);
List splist = web.Lists.GetByTitle(SharePointListName);
ListItem oListItem = splist.GetItemById(ID);
oListItem[CoulmnName] = "Current";
oListItem[ColumnRelatedField] = EntityInstanceIdEncoder.EncodeEntityInstanceId(new object[] { "Current" });
oListItem.Update();
clientContext.ExecuteQuery();
Also refer the below link
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange