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:
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?
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
USER_ROLE_ACTOR_TYPE
Didn't work for me. I used
GROUP_ROLE_ACTOR_TYPE
instead, and it works! 👍
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
BTW @Alexey Matveev Appfire_ can you help with how to add groups into four different roles in the project at the same time?
If I use in the console
projectRoleService.addActorsToProjectRole(actorCollection, projectRoleObject, project, ProjectRoleActor.USER_ROLE_ACTOR_TYPE, errorCollection)
four times then only first one executes.
Thanks in advance
With kind regards
Slava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Slava Gefen,
I tried the code its working for me when I tried with
GROUP_ROLE_ACTOR_TYPE
But I need to change the role of users.
Please suggest
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Likhitha Kosanam great that it works for you. To change a role I suppose you need two actions: Remove user from a role and add them to another as described in the doc:
ProjectRoleService (Atlassian JIRA 7.1.2 API)
With kind regards
Slava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Anton - I had capitalized the 'a' in addActors by mistake
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.