2

How to get the site users and site groups in SPFx using PnP JS?

Thanks in advance.

2

Site Users:

You can get the site users using pnp.sp.web.siteUsers as given below:

$pnp.sp.web.siteUsers.get().then(function(data) {
    var users = "";
    for (var i = 0; i < data.length; i++) {
        users += data[i].Id + " - " + data[i].Title + "<br/>";
    }
    console.log(users);
});

Reference: Pnp-JS-Core: Gets all users from Site Collection.

Site Groups:

You can get the site users using pnp.sp.web.siteGroups as given below:

$pnp.sp.web.siteGroups.get().then(function(data) {
    var groups = "";
    for (var i = 0; i < data.length; i++) {
        groups += data[i].Title + " - " + data[i].OwnerTitle + "<br/>";
    }
    console.log(groups);
});

Reference: Pnp-JS-Core: Gets all groups from Site Collection.

| 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.