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
  • This will do it, but for environments with a very large number of users and/or groups it may take a while and consume a lot of memory. Our environment has only about 1k users, so we can get away with it.

    You will need the People Functions and Group Functions plugins to use this. Replace rule!CMN_checkIsNullOrEmpty with your favorite null/empty list checking function.

    Also note that groups will still be returned where the user's Member Type is Rule. Not sure how to get around that.

    with(
      local!groups: getgroupsformemberuser(ri!user),
      a!forEach(
        items: local!groups,
        expression: with(
          local!directMembers: getdirectgroupmemberuserspaging(fv!item,0,-1),
          if(
            and(
              not(rule!CMN_checkIsNullOrEmpty(local!directMembers)),
              contains(local!directMembers, ri!user)
            ),
            fv!item,
            {}
          )
        )
      )
    )

Reply
  • This will do it, but for environments with a very large number of users and/or groups it may take a while and consume a lot of memory. Our environment has only about 1k users, so we can get away with it.

    You will need the People Functions and Group Functions plugins to use this. Replace rule!CMN_checkIsNullOrEmpty with your favorite null/empty list checking function.

    Also note that groups will still be returned where the user's Member Type is Rule. Not sure how to get around that.

    with(
      local!groups: getgroupsformemberuser(ri!user),
      a!forEach(
        items: local!groups,
        expression: with(
          local!directMembers: getdirectgroupmemberuserspaging(fv!item,0,-1),
          if(
            and(
              not(rule!CMN_checkIsNullOrEmpty(local!directMembers)),
              contains(local!directMembers, ri!user)
            ),
            fv!item,
            {}
          )
        )
      )
    )

Children
No Data