getting display name from users in group

Kamil Mikołajczyk August 4, 2021

Hi,

i have simple script sending users in group to an array and then displaying using for() loop.

String list = ComponentAccessor.getGroupManager().getUserNamesInGroup("somegroup").toString();
String list2 = list.substring(1, list.length() - 1);
String[] array = list2.split(",");

 

problem is that script displays username not full display name. i was trying with getDisplayName() function but with no result

could you help me?

3 answers

2 accepted

0 votes
Answer accepted
Martin Bayer _MoroSystems_ s_r_o__
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 4, 2021

Hi @Kamil Mikołajczyk the following script will do what you need:

import com.atlassian.jira.component.ComponentAccessor

def applicationUsersList = ComponentAccessor.getGroupManager().getUsersInGroup("jira-administrators")
def applicationUsersDisplayNames = applicationUsersList.collect{ it.getDisplayName() }
0 votes
Answer accepted
Mohamed Benziane
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 4, 2021

Hi @Kamil Mikołajczyk 

Can you try this method

getUsersInGroup()
https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/security/groups/GroupManager.html

instead of 

getUserNamesInGroup()

Then you will have a collection of ApplicationUser and make a loop and use this

methodgetDisplayName()

https://docs.atlassian.com/software/jira/docs/api/7.6.1/com/atlassian/jira/user/ApplicationUser.html

0 votes
SKAdmin February 27, 2024

Trying to collect the same info, but nothing seems to work for getting display name. 

 

Attempts below. 

import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.crowd.embedded.api.Group

log.setLevel(Level.INFO)
def groupManager = ComponentAccessor.groupManager

def groups = ['_Group1', '_Group2']
def result = "<table class='aui'>"
groups.each{ groupName ->

def group = groupManager.getGroup(groupName)
def members = groupManager.getUserNamesInGroup(group)
//def membersDisplay = members.getDisplayName()
//def membersDisplay = members.methodgetDisplayName()
log.info("${group.name} membersDisplay $membersDisplay")
result += "<tr> <td>${group.name}</td><td>$membersDisplay</td></tr>"
}
result += "</table>"
return result

Suggest an answer

Log in or Sign up to answer