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

This widget could not be displayed.
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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

229 views 3 0
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