Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

get a group name if it contains a keyword

wajih zouaoui
Contributor
January 5, 2021

Hi Community,

 

i need to add as watchers a specific group members with a postfunction while creating an issue.

Each user has a client group with all named the same way as its ended with '-clients' .

So i need a method that it fetch the group that name ended with '-clients' and add the members as watchers in the created issue.

The contains i've added below returns only a bloean value and i need to have the name of the group 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level

def currentAppUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name

def groupManager = ComponentAccessor.getGroupManager()
def Keyword = "-administrators"
def searchgroup = groupManager.getGroupNamesForUser(currentAppUser).contains(Keyword)
//log.debug ("Test " + searchgroup)

//return searchgroup

if (searchgroup) {

def watcherManager = ComponentAccessor.getWatcherManager()

def userUtil = ComponentAccessor.userUtil

userUtil.getAllUsersInGroupNames([searchgroup]).each {user ->

watcherManager.startWatching(user, issue)

}
}
else {
log.debug ("The user is not a member of a client group" )
}

 

Thanks in advance.

Wajih

 

1 answer

1 accepted

0 votes
Answer accepted
Benz Kek (Adaptavist)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
January 6, 2021

You are using the wrong method for the filtering as .contains() are designed to return a Boolean value. The following should give you a list of group name (type String). 

def searchgroup = groupManager.getGroupNamesForUser(currentAppUser).findAll{
it.contains(Keyword)
}

I hope this helps! 

wajih zouaoui
Contributor
January 7, 2021

Hi @Benz Kek (Adaptavist) ,

 

Thanks a lot for the reply

yep i used find() method with regex to catch the group having that keyword on it then made a loop to catch all the group containing this keyword.

Like Benz Kek (Adaptavist) likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
7.13.0
TAGS
AUG Leaders

Atlassian Community Events