Add a value in Components part of a project

Deleted user June 9, 2017

Hi guys, 

I am trying to develop a groovy script (post function) which add a value in Components part of a Project.

I  have the following error :

No signature of method: com.atlassian.jira.ComponentManager.getProjectComponentManager() is applicable for argument types: () values: []

 

create(String name, String description, String lead, long assigneeType, Long projectId)

 I think the problem come from the fourth parameter, I have put 0 because I don't know how to get the right value.

 capture script.PNG

Here is my code : 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.bc.project.component.ProjectComponent
import  com.atlassian.jira.bc.project.component.ProjectComponentManager

OptionsManager optionsManager = ComponentAccessor.getOptionsManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
ComponentManager componentManager = ComponentManager.getInstance()

//MutableIssue issue = issue
def issue = ComponentAccessor.getIssueManager().getIssueObject("CTY-213")


def userProjectId = 13900
def component = componentManager.getProjectComponentManager().create("test toto","description","leadtoto",0,userProjectId)

3 answers

1 accepted

0 votes
Answer accepted
Deleted user June 12, 2017
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.bc.project.component.ProjectComponent
import  com.atlassian.jira.bc.project.component.ProjectComponentManager

OptionsManager optionsManager = ComponentAccessor.getOptionsManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
ComponentManager componentManager = ComponentManager.getInstance()
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
MutableIssue issue = issue
//def issue = ComponentAccessor.getIssueManager().getIssueObject("CTY-213")

CustomField newApplication = customFieldManager.getCustomFieldObject((long)20210) //PP et P
def cfValue = issue.getCustomFieldValue(newApplication).toString()
CustomField mainOwner = customFieldManager.getCustomFieldObject((long)20206) //PP et P
def cfValueMainOwner = issue.getCustomFieldValue(mainOwner).toString()
String []name=cfValueMainOwner.split("\\(")

def userProjectId = 13900
def component = projectComponentManager.create(cfValue,"",name[0],1,userProjectId)
return component
0 votes
Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 31, 2020

FYI

Run script to add Component to multiple projects

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.bc.project.component.ProjectComponentManager

/* new component */
String componentName = "EE"
String description = "desc"
long projectId = 0

ProjectComponentManager pComMgr = ComponentAccessor.getProjectComponentManager()
ProjectComponent component
def projectManager = ComponentAccessor.getProjectManager()

String[] projects = ["CSSO", "SEUK", "SEBN", "SEP", "SESA", "SEG", "PC", "SEAG", "SESG", "SEI", "SEF", "SEPOL",
"SEGR", "SENA", "SEROM", "SEB", "SEH", "SECZ", "SEAD"]

projects.each() {String projectName ->
     projectId = projectManager.getProjectByCurrentKey(projectName).getId()
     component = pComMgr.create(componentName, description, null , 0, projectId)
}
Dusty Brossart March 16, 2021

Hello @Tom Lister 

Is there a way to specify all projects or all projects within a particular category without providing the project key?

Thanks,

-Dusty

Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 16, 2021

Hi

You  can loop through projects by category like this.



import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.util.SimpleErrorCollection

String [] categories = ["WSC", "P6", "BOLD"]
// SSO1

ProjectManager pMgr = ComponentAccessor.getProjectManager()
//def proj = pMgr.getProjectObjects()
Collection<String> actorNames
categories.each() {category ->
def p6 = pMgr.getProjectCategoryObjectByName(category)
def proj = pMgr.getProjectObjectsFromProjectCategory(p6.getId())
      proj.each() {Project p ->

     // blah

     }
}
Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 16, 2021

If you have Scriptrunner you can try this to copy components between projects

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.bc.project.component.ProjectComponentManager
import org.apache.log4j.Logger
import com.onresolve.scriptrunner.parameters.annotation.ProjectPicker
import com.atlassian.jira.project.Project

def logit = Logger.getLogger("com.cheil.eu.logging")

long projectId = 0

ProjectComponentManager pComMgr = ComponentAccessor.getProjectComponentManager()
@ProjectPicker(label = "Source Project", description = "Select project to copy Components from")
Project source
@ProjectPicker(label = "Target Project", description = "Select project to copy Components to")
Project target

def projectManager = ComponentAccessor.getProjectManager()

Collection<ProjectComponent> comps = pComMgr.findAllForProject(source.getId())
comps.each() { ProjectComponent component ->
def test = pComMgr.findByComponentName(projectId, component.getName())
if (!test) {
def comp = pComMgr.create(component.getName(), null, null , 0, target.getId())
logit.info("Add " + component.getName() + " to " + target.getName())
} else {
logit.info(component.getName() + " already exists in " + target.getName())
}
}

0 votes
Deleted user June 9, 2017

Shame on me, the function getProjectComponentManager seems not existing anymore. I have to find another function to do what I want. Any ideas ?

Jackson Farnsworth
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.
October 6, 2017

Strange, it still exists in JIRA 7.3.6

ComponentAccessor Documentation

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events