ScriptRunner - How to retrieve users in certain roles

Roberto L
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 Leaders.
September 21, 2017

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!

-Roberto

2 answers

2 votes
Bhushan Nagaraj
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 21, 2017
Roberto L
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 Leaders.
September 22, 2017

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.

-Roberto

Bhushan Nagaraj
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 22, 2017

Hey Roberto,

Continuing from the example provided in the link.

ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(devsRole, project)
def users = actors.getUsers().toList()
users.each {
it.emailAddress
}
Bhushan Nagaraj
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 22, 2017
0 votes
DYL August 9, 2022
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