Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to set project category in groovy script

Fabian Graevenitz May 9, 2022

Hello out there,

 

I want to automatically set the project category in a groovy script. I found out that Project class has a field for category and there is an interface for retrieving the categories. But I cannot find how to get an instance of that interface.

This is what I found so far:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.entity.ProjectCategoryFactory
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectCategory
import com.atlassian.jira.project.ProjectCategoryStore
import com.atlassian.jira.project.ProjectManager

Long categoryId = ProjectCategoryFactory.NONE_PROJECT_CATEGORY_ID

ProjectManager projectManager = ComponentAccessor.getProjectManager()

Project project = projectManager.getProjectObjByKey("MYKEY")

ProjectCategoryStore categoryStore = // TODO retrieve Project Category Store Instance
ProjectCategory myCategory = categoryStore.getProjectCategore(categoryId)

project.proctCategory = myCategory

 

1 answer

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
May 10, 2022

Hi @Fabian Graevenitz

A similar question was asked and answered previously in this Community Post.

Below is the sample code suggested:-

import com.atlassian.jira.component.ComponentAccessor

def projectManager = ComponentAccessor.projectManager

def projectList = projectManager.getProjectObjectsFromProjectCategory(10300)

def newCat = projectManager.getProjectCategoryObjectByName('Close')

projectList.each{
projectManager.setProjectCategory(it,newCat )
}

Thank you and Kind regards,

Ram

Fabian Graevenitz May 12, 2022

Thank you, that solved my problem :-)

 

I have another question: While performing my tests with frequent code changes I experience the annoying problem that ScriptRunner did not compile my recent changes but ran with an older version. How can I force recompilation of the current code?

Likhitha Kosanam June 15, 2023

Hi @Fabian Graevenitz 

 

Where to pass the projects? I need to set Project category for few projects .

Please suggest.

 

Regards

Likhitha

Suggest an answer

Log in or Sign up to answer