How i can convert User to FieldUserValue inside my CSOM code [duplicate]
-
08-02-2021 - |
Question
I have the following CSOM code:
Group group = web.SiteGroups.GetByName(subsitename);
List<FieldUserValue> currentgroupUsers = new List<FieldUserValue>();
foreach (User user2 in group.Users)
{
currentgroupUsers.Add(***********);
}
So how I can convert/cast a User
object to FieldUserValue
object?
Solution
Try something like below:
List<FieldUserValue> currentgroupUsers = new List<FieldUserValue>();
foreach (User user2 in group.Users)
{
var userLookupValue = new FieldLookupValue { LookupId = user2.Id };
currentgroupUsers.Add(userLookupValue);
}
oListItem["PersonOrGroupField"] = currentgroupUsers.ToArray();
oListItem.Update();
context.ExecuteQuery();
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange