Retrieving list of users in group macro

Hi there,

I'm new to Confluence but I'm starting to get a hang of it.

Right now I have a page on a space that is for our team. I have a section where I am putting "profile picture" macros to show each member of the group.

I was wonder how I could make a macro that would loop through the members of a group and call that macro, given a group name to look at.

So here is the psuedocode:

param1 = <PASSED IN PARAM>

foreach member in param1

{

profile_picture(member)

}

So the macro would take in the group name, loop thorugh the members, and call the "profile picture" macro for each member.

I know there is a "user list" macro, but it does not have exactly what I am looking for.

Any help would be greatly appreciated.

Thank you.

2 answers

1 accepted

1 vote
Accepted answer
David Simpson Community Champion Jun 18, 2014

Try this user macro:

## Users Pictures for Group - Confluence User Macro
##
##   Produces a pile of user profile pictures for members of a specific group
##
## WARNING:
##
##   Use very sparingly as this *will* slow down large Confluence instances.
##   Yes, it will try to print out 100,000 users if you have that many in the group
##
##   I generally remove this user macro after using once and add only when needed.
##   Or enable it for admins only.
##
## @param Group:title=Group Name|type=string|required=true|desc=The group name (yes, really)

  
#set($containerManagerClass = $action.class.forName('com.atlassian.spring.container.ContainerManager'))
#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))
#set($containerManager = $getInstanceMethod.invoke(null,null))
#set($containerContext = $containerManager.containerContext)
  
#set($userAccessor = $containerManager.containerContext.getComponent('userAccessor'))
#set($groupManager = $containerManager.containerContext.getComponent("groupManager"))
#set($group = $groupManager.getGroup($paramGroup))
#set($users = $userAccessor.getMemberNamesAsList($group) ) 

#foreach( $username in $users )

	#set($confluenceUser = $userAccessor.getUserByName($username))
	&lt;ac:structured-macro ac:name="profile-picture"&gt;&lt;ac:parameter ac:name="User"&gt;&lt;ri:user ri:userkey="$confluenceUser.key" /&gt;&lt;/ac:parameter&gt;&lt;/ac:structured-macro&gt;

#end

It should produce a pile of user profile pictures for members of a specific group.

Works exactly how I wanted it to. Thanks!

P.S. I understand the concern for the large sized groups. For a group like mine, it will not be as bad since we are a group of > 10 people. If you passed in something like "confluence-users" and you had a lot of people using Confluence, it might get hairy then.

In any event, thanks so much.

David Simpson Community Champion Jun 19, 2014

Hey @Kyle Crowley,

This was copied wholesale from here:
http://davidsimpson.me/2014/04/24/list-users-atlassian-confluence-user-macro/

The comments came through too.

Works exactly how I wanted it to. Thanks!

P.S. I understand the concern for the large sized groups. For a group like mine, it will not be as bad since we are a group of > 10 people. If you passed in something like "confluence-users" and you had a lot of people using Confluence, it might get hairy then.

In any event, thanks so much.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in New to Confluence

How to use Confluence Cloud for stakeholder management

Most of us don’t need much convincing that stakeholder management is important. It just makes sense that keeping everyone in-the-know on projects and assigning clearly defined roles is key to having ...

1,122 views 2 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you