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

This widget could not be displayed.
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

This widget could not be displayed.
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
Community showcase
Posted yesterday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

78 views 0 1
Join discussion

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