Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Assign permission scheme to all Projects in a Project Category (Code/Scriptrunner)



I know how to assign a permission scheme of a Template Project to another Project:


import org.springframework.stereotype.Component;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.workflow.AssignableWorkflowScheme;
import com.atlassian.jira.workflow.DraftWorkflowScheme;
import com.atlassian.jira.workflow.JiraWorkflow;
import com.atlassian.jira.workflow.WorkflowScheme;
import com.atlassian.jira.workflow.WorkflowSchemeManager;

def projectDefault = ComponentAccessor.getProjectManager().getProjectObjByKey("DPDefault");
def projectNeu = ComponentAccessor.getProjectManager().getProjectObjByKey("DPNeu");
ComponentAccessor.getWorkflowSchemeManager().addSchemeToProject(projectNeu, ComponentAccessor.getWorkflowSchemeManager().getSchemeFor(projectDefault));

But how do I do this to every single project of a project category? Or do I really need to change the permission scheme for each project in it? Thanks! 

2 answers

1 accepted

0 votes
Answer accepted
Leo Community Leader Nov 06, 2020

Hi @Sngy ,

Below code snippet may give you some idea, I didn't test this in my server though

import com.atlassian.jira.component.ComponentAccessor
def prcat = ComponentAccessor.getProjectManager().getProjectCategoryObjectByName("Code/Scriptrunner")
def prList = ComponentAccessor.getProjectManager().getProjectsFromProjectCategory(prcat)

prList.each{ proj ->
//code here

Here is the working code, folks!! It perfectly works.

*Just copy and paste* in your Script Runner's Script Console. Replace the below Project keys with your list (you can put up to *50 Project keys in one go*.. it processed first 50 keys, when I added 75 keys) and replace the Target Permission Scheme name.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project

def list = ["Proj Key 1", "Proj Key 2", "Proj Key 3", "Proj Key 4"]

for(item in list){
def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey(item)

log.warn("Project is:"+project)

String permissionScheme = "Target Permission Scheme"

ComponentAccessor.getPermissionSchemeManager().addSchemeToProject(project, ComponentAccessor.getPermissionSchemeManager().getSchemeObject(permissionScheme))

Suggest an answer

Log in or Sign up to answer

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you