Search all groups using findGroups in GroupPickerSearchService using Groovy Edited

I'm attempting to search all groups (not the groups for a specific user) via a groovy script in the Script Runner console using the following method: 

List<com.atlassian.crowd.embedded.api.Group> findGroups(String query)

https://docs.atlassian.com/jira/server/com/atlassian/jira/bc/group/search/GroupPickerSearchServiceImpl.html

My script:

import com.atlassian.jira.bc.group.search.GroupPickerSearchServiceImpl

def searchString = "members"
def groupList = GroupPickerSearchServiceImpl.findGroups(searchString)

fails suggesting a string be supplied..

Error

No signature of method: static com.atlassian.jira.bc.group.search.GroupPickerSearchServiceImpl.findGroups() is applicable for argument types: (java.lang.String) values: [members] Possible solutions: findGroups(java.lang.String)

 

What am I doing wrong? Thanks for any help!

 

1 answer

1 accepted

0 votes
Accepted answer
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("a search string")

//print group names to log
for (Group group in groupList){
log.error group.getName().toString()
}

Sorted - need to import via ComponentAccessor first

How can I get the name of all groups inside a plugin? Same way doesn't work on Jira 7.6.3. it gives me the list but I can't access to the items(Group).

GroupPickerSearchService groupSearch = ComponentAccessor.getComponent(GroupPickerSearchService.class);
List<Group> groupList = groupSearch.findGroups("");

for (Group group : groupList){
System.out.println("Group:" + group.getName());

 This are the values that it takes when I debug the code. ImmutableGroup??

image.png

For some reason when I do this, it works.

GroupPickerSearchService groupSearch = ComponentAccessor.getComponent(GroupPickerSearchService.class);
List<Group> groupList = new ArrayList<>();
groupList.addAll(groupSearch.findGroups(""));

for (Group gg : groupList){
System.out.println("Group:" + gg.getName());
}

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Monday in Jira Software

Implementing Jira in Small Business

Introduction This article will give insight on how a small software development department implemented Atlassian products to enhance and streamline the business process. The privately held company h...

313 views 2 8
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