Create
cancel
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

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
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 ?

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)
}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,919 views 11 5
Join discussion

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