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 vote
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 vote
Alexey Matveev Community Champion Nov 10, 2017

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

64 views 0 5
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