5

How can I insert multiple users and groups in a user field of a Sharepoint Online list using Pnp-Js-Core?

greetings and thanks.

2 Answers 2

8

You can use it as below:

$pnp.sp.web.lists.getByTitle("Test").items.add({
    Title: "test",    
    MultiUserId: { 
        results: [ 9, 6 ]  // User/Groups ids as an array of numbers
    }
}).then(i => {
    console.log(i);
});

You need to pass an array of user ids or group ids.

Also, if your internal column name is MultiUser you need to set the column name as MultiUserId i.e append Id to your internal column name.

Also, ensure that your column settings are set as below:

enter image description here

3

Check the PnP Js documentation Work with Items here

User field will set the value based on the user/group id, very similiar with lookup field:

pnp.sp.web.lists.getByTitle("PeopleFields").items.add({
    Title: Util.getGUID(),
    User1Id: 9, // allows a single user
    User2Id: { 
        results: [ 16, 45 ] // allows multiple users
    }
}).then(i => {
    console.log(i);
});
3
  • Thank you very much, but in the results array, I insert the user IDs, how do I insert the groups as well? Commented Nov 15, 2017 at 13:09
  • set group is the same to user, you can specify a group id in the above result array.
    – Jerry
    Commented Nov 16, 2017 at 8:46
  • Beware that the above does not apply to later versions of sppnp. Commented Dec 7, 2023 at 13:38

Your Answer

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

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