How to add Groups to a project role in groovy, script runner console

I'm trying to add (AD) groups to project roles using the Script Runner (5.04) Console, using Jira 7.3.1. I'm trying to use the method:

void addActorsToProjectRole(Collection<String> actors,
                            ProjectRole projectRole,
                            Project project,
                            String actorType,
                            ErrorCollection errorCollection)

source:

https://docs.atlassian.com/jira/7.3.1/com/atlassian/jira/bc/projectroles/ProjectRoleService.html#addActorsToProjectRole-java.util.Collection-com.atlassian.jira.security.roles.ProjectRole-com.atlassian.jira.project.Project-java.lang.String-com.atlassian.jira.util.ErrorCollection-

import com.atlassian.jira.bc.projectroles.ProjectRoleService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.util.SimpleErrorCollection
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.Project

def projectRoleService =ComponentAccessor.getComponent(ProjectRoleService);
def projectRoleManager =ComponentAccessor.getComponent(ProjectRoleManager);
def projectManager =ComponentAccessor.getComponent(ProjectManager);

ProjectRole projectRoleObject = projectRoleManager.getProjectRole("Role Name")
Project project = projectManager.getProjectObjByKey("XYZ")
def errorCollection = new SimpleErrorCollection();

projectRoleService.AddActorsToProjectRole(['Group A'], projectRoleObject, project, "GroupRoleActor.TYPE", errorCollection)

 

Static type checking errors are the issue. The problem lies with the errorCollection - I am also unable to use:

projectRoleManager.getProjectRoleActors(projectRoleObject, project, errorCollection)

Can anyone help?

 

2 answers

2 accepted

0 votes
Accepted answer
Anton Chemlev Community Champion Nov 10, 2017

Check this out - https://community.atlassian.com/t5/Product-Apps-questions/Jira-Script-runner-add-user-to-project-role/qaq-p/230748

Below script have no static check errors. Compare your script line by line. And just adapt it to use groups instead of users.

Thanks Anton - I had capitalized the 'a' in addActors by mistake

0 votes
Accepted answer

Hello,

I changed your code a bit and it was compiled successfuly

import com.atlassian.jira.bc.projectroles.ProjectRoleService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.util.SimpleErrorCollection
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.security.roles.ProjectRoleActor

def projectRoleService =ComponentAccessor.getComponent(ProjectRoleService);
def projectRoleManager =ComponentAccessor.getComponent(ProjectRoleManager);
def projectManager =ComponentAccessor.getComponent(ProjectManager);

ProjectRole projectRoleObject = projectRoleManager.getProjectRole("Role Name")
Project project = projectManager.getProjectObjByKey("XYZ")
def errorCollection = new SimpleErrorCollection();
Collection<String> actorCollection = new ArrayList<>();
actorCollection.add("Group A");

projectRoleService.addActorsToProjectRole(actorCollection, projectRoleObject, project, ProjectRoleActor.USER_ROLE_ACTOR_TYPE, errorCollection)

Thanks also Alexey

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,750 views 18 21
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you