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.
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)
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
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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())
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Strange, it still exists in JIRA 7.3.6
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.