How to get the direct group names for an user?

Certified Senior Developer

Is there a way to get the group names by passing the user name who are the direct users of that groups.

Example:

Parent Group: Group 1, Child Group:Group 2

Group 1:(user A, user B), Group 2:(user c)

If I pass user c, the result should be Group 2.

getgroupsformemberuser() returns all the groups irrespective of direct or indirect membership

  Discussion posts and replies are publicly visible

Parents
  • I think you need to break this down into a set of discrete steps:

    1. get a list of all the Groups in the hierarchy - in effect, "flatten" the hierarchy so you can test each Group independently
    2. iterate through the list of Groups so you can test them one at a time
    3. get a list of the direct User Members of each Group and test to see if the User you're working with is in that list. If so, return the Group.
Reply
  • I think you need to break this down into a set of discrete steps:

    1. get a list of all the Groups in the hierarchy - in effect, "flatten" the hierarchy so you can test each Group independently
    2. iterate through the list of Groups so you can test them one at a time
    3. get a list of the direct User Members of each Group and test to see if the User you're working with is in that list. If so, return the Group.
Children
No Data