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)
            {
            }
        }
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();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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