Forums

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

How to change project category through script console?

Marat August 21, 2019

I am trying to mass transfer projects from one category to another.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.ProjectCategory
import com.atlassian.jira.project.ProjectManager

def projectManager = ComponentAccessor.getProjectManager()
String[] projectList = projectManager.getProjectObjectsFromProjectCategory(10300)
def i
for (i = 0; i <= projectList.length; i++){
 projectManager.setProjectCategory(projectList[i].minus('Project: '), 'Close')
}

No signature of method: com.atlassian.jira.project.CachingProjectManager.setProjectCategory() is applicable for argument types: (java.lang.String, java.lang.String) values: [PFO, Close] Possible solutions: setProjectCategory(com.atlassian.jira.project.Project, com.atlassian.jira.project.ProjectCategory), getProjectCategory(java.lang.Long), createProjectCategory(java.lang.String, java.lang.String)

1 answer

1 accepted

4 votes
Answer accepted
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 21, 2019

By defining your projectList as String[] ... you are hamstringing yourself. Just get them as objects. 

Then you also need to get the object for the target new category.

And finally ... this is groovy ... leverage it for simplicity

Try this

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 )
}
Likhitha Kosanam June 15, 2023

Hi ,

 

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

Please suggest.

 

Regards

Likhitha

PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 15, 2023

Try this in the console:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.parameters.annotation.ShortTextInput

@ShortTextInput(description = "List of project Keys separated by commas", label = "Project Key List")
String projectListString

@ShortTextInput(description = '', label = "New Category")
String categoryName

def projectManager = ComponentAccessor.projectManager
def projectList = projectListString.tokenize(' ,').findResults { pkey ->
projectManager.getProjectByCurrentKey(pkey)
}
def newCat = projectManager.getProjectCategoryObjectByName(categoryName)
if (!newCat) {
return "There is no category by the name $categoryName. Manually assign that category to one project from the project settings first, then come back here to bulk-update more projects."
}
projectList.each {
projectManager.setProjectCategory(it, newCat)
}
Like Luca Andreatta likes this
Likhitha Kosanam June 20, 2023

Capture.PNG

Likhitha Kosanam June 20, 2023

please check this

PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 20, 2023

The point of the script I wrote was to give you a simple tool to use in the console.

This is what it is supposed to look like:

2023-06-20 09_53_18-Script Console.png

Like Deepali Kohli likes this
Likhitha Kosanam June 21, 2023

Hi @PD Sheehan ,

 

Thank you so much. :-)

 

Regards

Likhitha

Suggest an answer

Log in or Sign up to answer