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

0 vote
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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

845 views 2 9
Read article

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