0

I'm trying to find the owners and members for a given site. Once we have the site we get the given groups for each of the following:

  • associatedMemberGroup
  • associatedOwnerGroup

The code we use is below:

 const memberGroup = await context.associatedMemberGroup();

 const memberOwnerDetails = await context.siteGroups
       .getByName(memberGroup.LoginName)
       .expand('Users')();

The result brings back a member but the type is SecurityGroup (type 4) and not type user (type 2). We are expecting three members to be returned but instead we get the one member of type SecurityGroup and as such not getting the list of members we are expecting.

I've found the called made by SharePoint which is as follows but can't find the equivalent with pnp js.

https://my-domain.sharepoint.com/sites/my-site-name/_api/SP.Directory.DirectorySession/Group(${groupId})/members?$skip=0&$top=20&$inlinecount=allpages&$select=PrincipalName,Id,DisplayName,PictureUrl,UserType,Mail

Any suggestions on how/why it works this way and the calls that we should be using to get the correct information would be much appreciated.

1 Answers1

-2

It seems like you are using the SharePoint PnP JavaScript library to retrieve the members of a site group. However, you are encountering an issue where the returned member is of type "SecurityGroup" instead of type "User." This behavior is expected because SharePoint allows security groups to be added as members of other groups.

To retrieve the members of a group using the PnP JavaScript library, you can modify your code as follows:

const memberGroup = await context.associatedMemberGroup();

const group = await context.web.siteGroups.getByName(memberGroup.LoginName).expand('Users').get();

// Filter out the security groups from the users collection
const users = group.Users.filter(user => user.PrincipalType === 1);

console.log(users);
  • 1
    Many of your recent answers appear likely to have been entirely or partially written by AI (e.g., ChatGPT). Please be aware that [posting of AI-generated content is banned here](//meta.stackoverflow.com/q/421831). If you used an AI tool to assist with any answer, I would encourage you to delete it. – NotTheDr01ds Jun 11 '23 at 13:05
  • 1
    **Readers should review this answer carefully and critically, as AI-generated information often contains fundamental errors and misinformation.** If you observe quality issues and/or have reason to believe that this answer was generated by AI, please leave feedback accordingly. The moderation team can use your help to identify quality issues. – NotTheDr01ds Jun 11 '23 at 13:05
  • 1
    The filter will not work as the only user returned in the group is the security user not the 3 users we expect – user1005344 Jun 12 '23 at 08:18
  • 1
    great answer! just out of curiosity, did you get this from chatgpt? – starball Jun 21 '23 at 05:30
  • 1
    This answer looks like it was generated by an AI (like ChatGPT), not by an actual human being. You should be aware that [posting AI-generated output is officially **BANNED** on Stack Overflow](https://meta.stackoverflow.com/q/421831). If this answer was indeed generated by an AI, then I strongly suggest you delete it before you get yourself into even bigger trouble: **WE TAKE PLAGIARISM SERIOUSLY HERE.** Please read: [Why posting GPT and ChatGPT generated answers is not currently allowed](https://stackoverflow.com/help/gpt-policy). – tchrist Jul 18 '23 at 13:13