List names in confluence-users
Asked by lazy boy:

Hi there,

Can anyone suggest a user macro for generating all of the user's full names within 'confluence-users' and displaying them in a drop-down list?

Any help would be greatly appreciated!

Thanks,


Answers:
author: Stephen Deutsch
body: Something like this should work:

```
## @noparams#set ( $members = $userAccessor.getMemberNamesAsList($userAccessor.getGroup("confluence-users")) )&lt;style&gt;select:required:invalid {  color: gray;}option[value=""][disabled] {  display: none;}option {  color: black;}&lt;/style&gt;&lt;form class="aui" onsubmit="return false;"&gt;    &lt;fieldset&gt;        &lt;div class="field-group"&gt;            &lt;label for="users-list"&gt;Users:&lt;/label&gt;            &lt;select class="select" id="users-list" name="users-list" title="users list" required&gt;                &lt;option value="" disabled selected&gt;Select a user&lt;/option&gt;                #foreach ( $member in $members )                    #set ( $member = $userAccessor.getUserByName($member) )                    &lt;option value="$member.name"&gt;$member.fullName&lt;/option&gt;                #end            &lt;/select&gt;        &lt;/div&gt;    &lt;/fieldset&gt;&lt;/form&gt;
```

comments: author: lazy boy
body: Hi Stephen,This works perfectly, except one issue.The drop-down list is ordered by username. Could the list be ordered by full name?


author: Stephen Deutsch
body: Ordering by full name is harder than it seems. Here are two options, one that renders on the server side (might take a long time, depending on how many users you have):

```
## @noparams#set ( $members = $userAccessor.getMemberNamesAsList($userAccessor.getGroup("confluence-users")) )#set ( $container = $content.class.forName("java.util.TreeMap").newInstance() )#foreach ( $member in $members )    #set ( $member = $userAccessor.getUserByName($member) )    #set ( $dummy = $container.put($member.fullName, $member.name) )#end&lt;style&gt;select:required:invalid {  color: gray;}option[value=""][disabled] {  display: none;}option {  color: black;}&lt;/style&gt;&lt;form class="aui" onsubmit="return false;"&gt;    &lt;fieldset&gt;        &lt;div class="field-group"&gt;            &lt;label for="users-list"&gt;Users:&lt;/label&gt;            &lt;select class="select" id="users-list" name="users-list" title="users list" required&gt;                &lt;option value="" disabled selected&gt;Select a user&lt;/option&gt;                #foreach ( $member in $container.keySet() )                    &lt;option value="$container.get($member)"&gt;$member&lt;/option&gt;                #end            &lt;/select&gt;        &lt;/div&gt;    &lt;/fieldset&gt;&lt;/form&gt;
```

and here's one that sorts the list on the client side (i.e. in the browser) that might load the page a little faster:

```
## @noparams#set ( $members = $userAccessor.getMemberNamesAsList($userAccessor.getGroup("confluence-users")) )&lt;style&gt;select:required:invalid {  color: gray;}option[value=""][disabled] {  display: none;}option {  color: black;}&lt;/style&gt;&lt;form class="aui" onsubmit="return false;"&gt;    &lt;fieldset&gt;        &lt;div class="field-group"&gt;            &lt;label for="users-list"&gt;Users:&lt;/label&gt;            &lt;select class="select" id="users-list" name="users-list" title="users list" required&gt;                &lt;option value="" disabled selected&gt;Select a user&lt;/option&gt;            &lt;/select&gt;        &lt;/div&gt;    &lt;/fieldset&gt;&lt;/form&gt;&lt;script&gt;    var members = {    #foreach ( $member in $members )        #set ( $member = $userAccessor.getUserByName($member) )        "$member.fullName": "$member.name",     #end    }        function sortObject(obj) {        return Object.keys(obj).sort().reduce(function (result, key) {            result[key] = obj[key];            return result;        }, {});    }    var sortedMembers = sortObject(members);    for (var key in sortedMembers) {        if (sortedMembers.hasOwnProperty(key)) {            jQuery("#users-list").append('&lt;option value="' + sortedMembers[key] + '"&gt;' + key + '&lt;/option&gt;');        }    }&lt;/script&gt;
```


author: Guilherme V.
body: Hey there,

You can execute the following query in the database:

```
select u.user_name,g.group_name from cwd_user u,cwd_group g ,cwd_membership m where g.group_name = 'confluence-users' and m.parent_id=g.id group by u.user_name, g.group_name
```

However you can download a SQL manager for Confluence like this [one](https://marketplace.atlassian.com/plugins/org.swift.confluence.sql) and put it on a page.

Hope this will help you :smile:.

Cheers,


Tags: confluence-administration