Forums

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

Script to get project role of assignee of an issue

hbhardwaj3
Contributor
March 19, 2019

Hi,

I am using below script (scripted field) to fetch user' group, but I am not sure how should I get project role instead of assigned group of a user (assignee of an issue).

 

import com.atlassian.jira.component.ComponentAccessor

def groupObjs = ComponentAccessor.getGroupManager().getGroupsForUser(issue.getAssignee())
String[] groupNames = new String[groupObjs.size()]
for (int i = 0; i<groupObjs.size(); i++)
{
groupNames[i] = groupObjs[i].name
}
return groupNames.toString()

1 answer

1 accepted

2 votes
Answer accepted
Mark Markov
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.
March 19, 2019

Hello @hbhardwaj3 

Use ProjectRoleManager to get project roles, like this

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager


def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager.class)
def projectRoles = projectRoleManager.getProjectRoles(issue.getAssignee(), issue.getProjectObject())

return projectRoles.collect {it.name}.toString()
hbhardwaj3
Contributor
March 19, 2019

Thank you so much @Mark Markov ! you are awesome!!!

it worked for me :) 

Like ninghongju likes this

Suggest an answer

Log in or Sign up to answer