Set component by "create a sub-task" workflow post function

Hello,

I'm trying to create sub-tasks depending on the selection of some custom fields. For each selected custom field, there should be a corresponding sub-task. This is working great so far with the newest ScriptRunner-Addon and specified validators.

Here comes the issue: Additionaly I would like to set corresponding components for the created sub-tasks within the "create a sub-task" function.

I'm using JIRA 7.4.4 with ScriptRunner 5.1.6.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.project.Project
import com.atlassian.jira.bc.project.component.ProjectComponent

//set components - NOT WORKING
MutableIssue issue = issue
Project project = issue.getProjectObject()
ComponentManager componentManager = ComponentManager.getInstance();
def component = componentManager.getProjectComponentManager().findByComponentName(project.getId(),'ComponentName')
issue.setComponentObjects([component])

 I'm getting this error:

cannot_find_matching_method.png

1 answer

1 accepted

Accepted Answer
0 votes
Alexey Matveev Community Champion Dec 11, 2017

Hello,

You use deprecate ComponentManager. Try like this

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.project.Project
import com.atlassian.jira.bc.project.component.ProjectComponent

//set components - NOT WORKING
MutableIssue issue = issue
Project project = issue.getProjectObject()
def component = ComponentAccessor.getProjectComponentManager().findByComponentName(project.getId(),'ComponentName')
issue.setComponent([component])

Awesome! Thank you so much for such a fast solution for my problem! :)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Thursday in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

145 views 3 4
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you