Hi,
I have two user custom fields like "Project Manager" and "Project Sponsor".
When I create the issue, people in this fields are automatically added to the corresponding project roles.
Project Manager(custom user picker field) --> Project Managers (role)
Project Sponsor(custom user picker field) --> Project Sponsors (role)
Also I have Script Runner and Workflow Toolbox add-ons.
Try this code in the create transition's script post function.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.bc.projectroles.ProjectRoleService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleActor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.util.SimpleErrorCollection
import com.atlassian.jira.user.ApplicationUser
//get the value of Project Manager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def projectManagerField = customFieldManager.getCustomFieldObjectsByName("Project Manager")
def projectManagerValue = issue.getCustomFieldValue(projectManagerField[0]) as ApplicationUser
//get the value of Project Manager
def projectSponsorField = customFieldManager.getCustomFieldObjectsByName("Project Sponsor")
def projectSponsorValue = issue.getCustomFieldValue(projectSponsorField[0]) as ApplicationUser
def pmActors = []
def psActors = []
pmActors.add(projectManagerValue.getUsername().toString())
psActors.add(projectSponsorValue.getUsername().toString())
def projectManager = ComponentAccessor.getProjectManager()
def projectRoleService = ComponentAccessor.getComponent(ProjectRoleService)
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def errorCollection = new SimpleErrorCollection()
def project = issue.getProjectObject()
def projectManagerRole = projectRoleManager.getProjectRole("Project Managers")
def projectSponsorsRole = projectRoleManager.getProjectRole("Project Sponsors")
//Add to Project Managers role
projectRoleService.addActorsToProjectRole(pmActors,
projectManagerRole,
project,
ProjectRoleActor.USER_ROLE_ACTOR_TYPE,
errorCollection)
//Add to Project Sponsors role
projectRoleService.addActorsToProjectRole(psActors,
projectSponsorsRole,
project,
ProjectRoleActor.USER_ROLE_ACTOR_TYPE,
errorCollection)
Let me know if it works. It is based on single user picker field.
Ravi
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.