Forums

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

Get users under project role through script

James Lebron
Contributor
July 27, 2022
Hello
My appeal is very simple, that is to query all users in the project role under the project in the script, and then set the corresponding value to the custom field, can you help me?
Below is the code I tried
import com.atlassian.jira.security.roles.ProjectRoleActor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.security.roles.ProjectRoleActors
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRole
import com.onresolve.scriptrunner.parameters.annotation.ProjectRolePicker
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.scriptrunner.parameters.annotation.CustomFieldPicker
import com.atlassian.jira.project.Project
import com.onresolve.scriptrunner.parameters.annotation.ProjectPicker

@ProjectPicker(
label = 'Project', description = 'Pick a project', placeholder = 'Pick a project', includeArchived = false
)
Project project

@CustomFieldPicker(label = 'Custom Field', description = 'Pick a custom field', placeholder='Select custom field')
CustomField customField

@ProjectRolePicker(label = 'Project role', description = 'Project role picker')
ProjectRole projectRole

ProjectRoleManager projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager.class)
ProjectManager projectManager = ComponentAccessor.getProjectManager()
ProjectRoleActors projectRoleActors = projectRoleManager.getProjectRoleActors(projectRole, project)
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

/*

Get all users in the project role under the project,

and then fill these users into the custom field

*/

// but I don't know how to write the next code

projectRoleActors.each { roleActor ->

//...

}

def userList = []

issue.setCustomFieldValue(customField, userList)

 

1 answer

1 accepted

0 votes
Answer accepted
Nic Brough -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 Leaders.
July 27, 2022

You can do this, yes, but why?  Of what possible use is a list of roles of users in a project on an issue?  It won't tell you what they can do in the project and it can and will change.

I can't see any use for this, so I don't think it's worth going to look at the code you might need.

What problem are you trying to solve with this?  We can probably solve it a lot easier than kluding role records on to issues.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira product discovery, jpd premium, product management, idea management, product discovery, jira premium, product planning, atlassian community, product development, roadmap planning, product prioritization, feature management

Introducing Jira Product Discovery Premium ✨

Jira Product Discovery Premium is now available! Get more visibility, control, and support to build products at scale.

Learn more
AUG Leaders

Atlassian Community Events