Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

ScriptRunner - How to retrieve users in certain roles

Hello Community,

I am trying to figure out how to retrieve all the user in certain roles.

I am working on a script that will grab all the users associated with a certain role, in this case Project Administrator role, for all the projects in Jira and send them an email when a certain event is triggered.

I currently have everything completed except for fetching the users in the Project Administrator role. 

Would anyone know how one is to approach this?

Any help is greatly appreciated!


2 answers

hi @Bhushan Nagaraj,

i read the attached community post. I was able to retrieve all users from a specific role in every project in my Jira Instance.

I can’t seem to figure how to loop through them.

could you explain how I can fetch the users and loop through everyone.

i require the emails of every user and i am thinking I can do so by looping through all the users, getting their names, and passing that to UserManager.getUserByKey() and from there fetch the emails.


Hey Roberto,

Continuing from the example provided in the link.

ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(devsRole, project)
def users = actors.getUsers().toList()
users.each {
Project project = currentIssue.getProjectObject()
def projectRoleList = projectRoleManager.getProjectRoles().findAll {
it.getName() == "Administrators"
log.warn("projectRole: ${projectRoleList}================>>>>>>")
if (projectRoleList.size() == 0) {
return adminUserEmailList
def projectRoleActors = projectRoleManager.getProjectRoleActors(projectRoleList[0], project)
log.warn("projectRoleActors: ${projectRoleActors}")
def users = projectRoleActors.getUsers().toList()
users.each { adminUserEmailList.add(it.emailAddress) }

Suggest an answer

Log in or Sign up to answer