You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
I ran into a use case where I needed this query and didn't see it posted already. Hopefully it helps! This can be used in the script console as a part of the script runner add-on.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.group.search.GroupPickerSearchService
import com.atlassian.crowd.embedded.api.Group
def groupSearch = ComponentAccessor.getComponent(GroupPickerSearchService)
def groupList = groupSearch.findGroups("")
def groupManager = ComponentAccessor.getGroupManager()
for (Group group in groupList){
log.error group.getName().toString()//print group names to log
log.error groupManager.getUsersInGroup(group)//print group members to log
}
the code which i mentioned below is not working after the upgrade.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.crowd.embedded.api.Group;
Issue issue = issue;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def groupManager = ComponentAccessor.getGroupManager()
def userName = ""
CustomField releasersName = customFieldManager.getCustomFieldObjectByName( "Releasers Name" );
CustomField releaser = customFieldManager.getCustomFieldObjectByName( "Releaser" );
def userManager = ComponentAccessor.getUserManager()
//def group = userManager.getGroup((String) issue.getCustomFieldValue(releaser))
def cfgvalue =(List<Group>) issue.getCustomFieldValue(releaser);
for(Group group:cfgvalue){
Collection <ApplicationUser> usersInGroup = groupManager.getUsersInGroup(group)
for (User user : usersInGroup){
log.warn(user.getDisplayName())
if(userName == "") {
userName = user.getDisplayName()
} else {
userName = userName + "," +user.getDisplayName()
}
}
}
//log.warn(userName)
//issue.setCustomFieldValue(releasersName,userName)
releasersName.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(releasersName), userName),changeHolder);
This one Works better to find all groups and members in scriptrunner script consol . (Thanks Mr G)
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.getGroupManager()
def result = "<table class='aui'>"
groupManager.allGroups.each{ group ->
def members = groupManager.getUserNamesInGroup(group)
log.info("${group.name} members $members")
result += "<tr> <td>${group.name}</td><td>$members</td></tr>"
}
result += "</table>"
return result
I want only to display 10 groups with their members.
Also , I am trying to fetch the Display names and not the usernames.
Can you please advise @Chris Scheepers
Thanks,
Ajinkya