Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,557,897
Community Members
 
Community Events
184
Community Groups

JIRA Groovy scripting

Edited

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

1 answer

1 vote
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 14, 2023

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 

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 02, 2023

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"

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events