List names in confluence-users

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,

 

 

 

3 answers

Something like this should work:

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

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

0 votes

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 and put it on a page.

Hope this will help you smile.

Cheers,

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

<style>
select:required:invalid {
  color: gray;
}
option[value=""][disabled] {
  display: none;
}
option {
  color: black;
}
</style>

<form class="aui" onsubmit="return false;">
    <fieldset>
        <div class="field-group">
            <label for="users-list">Users:</label>
            <select class="select" id="users-list" name="users-list" title="users list" required>
                <option value="" disabled selected>Select a user</option>
                #foreach ( $member in $container.keySet() )
                    <option value="$container.get($member)">$member</option>
                #end
            </select>
        </div>
    </fieldset>
</form>

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")) )

<style>
select:required:invalid {
  color: gray;
}
option[value=""][disabled] {
  display: none;
}
option {
  color: black;
}
</style>

<form class="aui" onsubmit="return false;">
    <fieldset>
        <div class="field-group">
            <label for="users-list">Users:</label>
            <select class="select" id="users-list" name="users-list" title="users list" required>
                <option value="" disabled selected>Select a user</option>
            </select>
        </div>
    </fieldset>
</form>

<script>
    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('<option value="' + sortedMembers[key] + '">' + key + '</option>');
        }
    }
</script>

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Tuesday in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

212 views 2 10
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