Question

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

Thanks in advance.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top