How to sort array items in a user macro using velocity?

I want to displays members of a group, sortet by the displayName instead of the username.
Something like this:

{code}

#set($memberslist = $userAccessor.getMemberNamesAsList($group))

#set($myArrayList = [])
#foreach( $member in $memberslist )
  $myArrayList.add( {"fullname" : $action.getUserFullName($member) }) 
#end

#foreach( $item in  $sortTool.sort($myArrayList, "fullname:asc") )
   <li> $item.toString()
 #end

{code}

  

This does not work for me. Can you help me?

2 answers

This widget could not be displayed.

Have you looked at this one: https://answers.atlassian.com/questions/218237/sort-list-of-objects-in-velocity

It helped me with my sorting issues :)

This widget could not be displayed.

Sana,

many thanks. Sorry, I didn't reply to your hint.

Unfortunately that solution didn't work for me. I got an exception error.

So that request is still open (for me). Any idea (someone else)?

I have now a new similar task: I get the descendants of a given page in a user macro. I want to sort that pages by the last-modify-date. Again: how can that be done?

My user macro so far:

 

## Macro title: Page descendants
## Macro has a body: N
## List all descendant pages below a give page 
## Developed by: Stefan Baader
## Date created: 13/10/2015
## Installed by: Stefan Baader

## @param Page:title=Page|type=confluence-content|required=true|desc=Select a page do use

#set( $pages = $pageManager.getPage($space.key, $paramPage).getDescendants() )

Descendants of page "${paramPage}"

<table>
<tr>
<th>Seite</th>
<th style="white-space:nowrap;">Vers. Nr.</th>
<th style="white-space:nowrap;">Aktualisiert am</th>
</tr>
#foreach( $page in $pages) 
<tr>
<td>
<a href="$req.contextPath/pages/viewpage.action?pageId=$page.id">$page.title</a> 
</td>
<td>
$page.getVersion()
</td>
<td style="white-space:nowrap;">
$page.getLastModificationDate()  
</td>
</tr>
#end
</table>

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

459 views 6 6
Join discussion

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