I need to create a script field in script runner that displays all of the users within a specific role for that project. How should this be coded?
Thanks.
Community moderators have prevented the ability to post new answers.
At some place you will have to use ProjectRoleManager#getProjectRoleActors()
and DefaultRoleActors#getApplicationUsers()
. Like this:
ProjectRoleManager projectRoleManager; ProjectRoleActors roleActors = projectRoleManager.getProjectRoleActors(myProjectRole, myProject); Set<ApplicationUsers> usersInRole = projectActors.getApplicationUsers(); // or for JIRA 5: Set<User> usersInRole = projectActors.getUsers();
For scripted fields itself take a look at Script Runner's docu.
Thanks for your input. This code returns the correct list of users, but also an error:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.security.roles.ProjectRoleManager import com.atlassian.jira.user.ApplicationUsers def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager) def projectRoleId = 10300 // ID of Automatic Watcher project role def role = projectRoleManager.getProjectRole(projectRoleId) def actors = projectRoleManager.getProjectRoleActors(role, issue.projectObject) def usersInRole = actors.getApplicationUsers(); return usersInRole;
Here is the error I get:
The indexer for this field expects a java.lang.String but the script returned a java.util.HashSet - this will cause problems.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You probably have the wrong Searcher set in your scripted field. Try the Multi User Picker Searcher.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Perhaps you don't need it indexed at all, in which case choose None. If you do need it indexed you may need to convert between different types of users... try without indexer first.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Andreas was right, I had the searcher for the custom field set to Text Searcher instead of the multi-user searcher. Once I changed it to multi-user searcher, the error went away. Thanks.
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.