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
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!
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.