2

I have a Sharepoint list called AproverList where ApproverName2 field is "Person or Group" type with multiple selection option

enter image description here

enter image description here

This is the code I'm using, but it allows me to enter only one user into the field ApproverName2. Do you know how to achieve the insertion of multiple users into this multi selection field?

        using (ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(siteUri.ToString(), accessToken))
        {
            Web web = clientContext.Web;
            try
            {
                List targetList = web.Lists.GetByTitle("ApproverList");

                ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                ListItem newListItem = targetList.AddItem(itemCreateInfo);
                newListItem["ApproverId"] = "1";
                newListItem["Title"] = "GBO";
                newListItem["ApproverName2"] = web.EnsureUser("jsamakm");
                newListItem.Update();

                clientContext.Load(newListItem);
                clientContext.ExecuteQuery();
            }
            catch (Exception ex)
            {
            }
        }

1 Answer 1

6

Try to use SPFieldUserValueCollection to set multiple person / group field

 SPFieldUserValueCollection usercollection = new SPFieldUserValueCollection();

This is a similar example

SPFieldUserValueCollection value = new SPFieldUserValueCollection();
value.Add(new SPFieldUserValue(web, user1.ID, user1.Name)));
value.Add(new SPFieldUserValue(web, user2.ID, user2.Name)));

objItem["name"] = value;
objItem.Update();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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