Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,653
Community Members
 
Community Events
176
Community Groups

Add a value in Components part of a project

Edited
Deleted user Jun 09, 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 Jun 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 Mar 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)
}

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 Mar 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 Mar 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 Jun 09, 2017

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

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events