It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Answer accepted
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());
}

Thank you. It works.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you