0

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?

3
  • Is there any particular reason you need FieldUserValue object? maybe there is another workaround for what you are trying yo achieve. May 15 '20 at 12:36
  • @GaneshSanap i need it as List<FieldUserValue> because i will assign the currentgroupUsers to a field of type people or group which accept multiple entries..
    – John John
    May 15 '20 at 13:34
  • @KarthikJaganathan the link is using server-sdie object while i am using CSOM, and in cSOM the FieldUserValue does not accept this new SPFieldUserValue(SPContext.Current.Web, listItem["Author"].ToString())
    – John John
    May 15 '20 at 13:35
2

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();

Not the answer you're looking for? Browse other questions tagged or ask your own question.