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

This widget could not be displayed.
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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 25, 2018 in Marketplace Apps

Jira Cloud and Bitbucket Cloud Integration with Microsoft Teams

One of the newest products in the Microsoft family - Microsoft Teams,  is a chat-based hub for teamwork that integrates all the people, content, and tools your team needs to be more engaged and ...

734 views 0 3
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