JIRA Groovy scripting

Nasser Aloraini April 14, 2023

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
PD Sheehan
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.
April 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")
}
Nasser Aloraini April 15, 2023

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 

PD Sheehan
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.
May 2, 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