I created the groovy code below to have the post-function set the issue's component. However, I get an error in the call to issue.setComponentObjects():
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
MutableIssue issue = issue
Project project = issue.getProjectObject()
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def componentFRIproduct = projectComponentManager.findByComponentName(project.getId(), "FRI Product")
if (componentFRIproduct != null) {
UserMessageUtil.info("Post-02: my issue type, setting component...")
issue.setComponentObjects([componentFRIproduct])
}
It seems that issue.setComponentObjects() expects a list of component objects, but projectComponentManager.findByComponentName() returns a ProjectComponent object.
How can I make this work?
Found the solution: use issue.setComponent().
Here is the full working code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.project.Project
final String compName = "FRI Product"
final issueTypes = ["FRI Incident", "FRI Service Request"]
MutableIssue issue = issue
Project project = issue.getProjectObject()
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def componentFRIproduct = projectComponentManager.findByComponentName(project.getId(), compName)
def isMyType = issue.issueType.name in issueTypes
if (isMyType && (componentFRIproduct != null)) {
issue.setComponent([componentFRIproduct])
}
Here's a reference post:
Which I based my code on. But I suspect that the Jira API has changed and projectComponent and component are not the same now.
I'm using Jira 7.4.1
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Amir Katz (Outseer) Please Check we have a solution.
https://community.atlassian.com/t5/Jira-questions/set-Component-in-groovy-script/qaq-p/196655
Best
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Moses, but this is an old post (2013) and it doesn't work for me.
I modified my code to use this:
import com.atlassian.jira.ComponentManager
ComponentManager componentManager = ComponentManager.getInstance()
def component = componentManager.getProjectComponentManager().findByComponentName(project.getId(),'ComponentName')
And I now get error on line 3 (line 18 in my full code):
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.