You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hello Everyone,
I came up with script below and it supposed to add a user to a project role but i keep facing this issue at the end lines of the script. I'm running the latest scriptrunner version on JIRA Data Center. Thank you
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.ProjectRoleManager
def projectKey = "PROJECT_KEY"
def roleName = "PROJECT_ROLE_NAME"
def userId = "USER_ID"
def projectManager = ComponentAccessor.getProjectManager()
def project = projectManager.getProjectByCurrentKey(projectKey)
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def projectRole = projectRoleManager.getProjectRole(roleName)
if (project && projectRole) {
projectRoleManager.addActorToProjectRole(projectRole, project, userId)
} else {
log.error("Unable to find project or project role")
}
Error below in line 16 "projectRoleManager.addActorsToProjectRole"
[Static type checking] - Cannot find matching method
com.atlassian.jira.security.roles.ProjectRoleManager#addActorToProjectRole(com.atlassian.jira.security
com.atlassian.jira.project.Project, java. lang. String). Please check if the declared type is correct and if the method exists
What version of Jira?
I'm not familiar with com.atlassian.jira.security.roles.ProjectRoleManager
In the jira versions I've worked with, I've only used com.atlassian.jira.security.roles.ProjectRoleManager.
And if doesn't offer an 'addActorToProjectRole' method.
Or did you mean to use ProjectRoleService.addActorsToProjectRole?
Here is an example:
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.ErrorCollections
def projectKey = "PROJECT_KEY"
def roleName = "PROJECT_ROLE_NAME"
def userId = "USER_ID"
def projectManager = ComponentAccessor.getProjectManager()
ProjectRoleService projectRoleService = ComponentAccessor.getComponent(ProjectRoleService)
ProjectRoleManager projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def project = projectManager.getProjectByCurrentKey(projectKey)
def projectRole = projectRoleManager.getProjectRole(roleName)
if (project && projectRole) {
def errorCollection = ErrorCollections.empty()
projectRoleService.addActorsToProjectRole([userId], projectRole, project, ProjectRoleActor.USER_ROLE_ACTOR_TYPE, ErrorCollections.empty())
if (errorCollection.hasAnyErrors()) {
log.error errorCollection.toString()
}
} else {
log.error("Unable to find project or project role")
}
Thanks for replying Peter,
Is tried both of:
ProjectRoleService.addActorsToProjectRole
ProjectRoleManger.addActorsToProjectRole
and i get the same error.
Also im new to scripting in JIRA and i looked up the internet a lot and i try many classes to see ehat works like "com.atlassian.jira.security.roles.ProjectRoleManager"
Also my JIRA version is
JIRA Service Management 5.4.1
JIRA Software 9.4.1
Both of them data center type
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you tried the script I supplied?
Just replace the following ALL_CAPS words with the items from your instance
def projectKey = "PROJECT_KEY"
def roleName = "PROJECT_ROLE_NAME"
def userId = "USER_ID"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.