Get members in multiple groups

Certified Senior Developer

I'm trying to think my way through a problem. What I need is, given a list of groups, I want to see a list of users that are members of all of those groups. The existing tools almost, but not quite do what I need. 

groupMembers() will give me the members of a single group, so I thought maybe if I got the members of each group and got the union() of them, that would solve my problem, but union only takes 2 lists and looping through with foreach  (I do so wish there were other types of loops!) would mean somehow getting the union of each member of the list, then unioning those results until I get down to just one list, but that sounds like a pain to code and probably not terribly efficient. 

isMemberOfGroups() is nice in that I can take a user and see if they are a member of all of a list of groups, but then I have to loop through basically all users (or at least all users in some initial group) and ultimately I am not sure how many users there could be or whether the maximum batch size of 10,000 will be enough. That doesn't seem like a whole lot of users to ultimately have as a limitation. 

Then there's getdistinctusers() which is kind of the opposite of what I want? It gives me all users across a set of groups with no duplicates, I think?

Are one of these methods the way to go? Am I missing something? 

  Discussion posts and replies are publicly visible

Parents Reply Children
No Data