4

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

greetings and thanks.

4

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

2

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);
});
  • Thank you very much, but in the results array, I insert the user IDs, how do I insert the groups as well? – Fabio Valencia Nov 15 '17 at 13:09
  • set group is the same to user, you can specify a group id in the above result array. – Jerry_MSFT Nov 16 '17 at 8:46

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.