Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,553,550
Community Members
 
Community Events
184
Community Groups

Script runner for setting up a component based on issue type

Hi,

I am trying to set a component (using script runner listener) baed on the issue type.

so when issue is created , if issue type is x then set up the component to 1

if issue type is y then set the components to 2 and 3

i have the following code so far:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.CustomFieldUtils
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.project.component.ProjectComponentManager

def issue = event.issue as Issue
def project = issue.getProjectObject()
def componentManager = ComponentAccessor.projectComponentManager
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def component1 = projectComponentManager.findByComponentName(project.getId(), "1")

if(issue.issueType.name == "x"){
issue.setComponents([component1])
}

 

and I am getting an error "cannot find matching method for issue.set.Components in 

<com.atlassian.jira.bc.project.component.ProjectComponentManager>

 

can anyone assist please? I am using Jira software 7.3, in house solution

Thnaks 

1 answer

1 accepted

1 vote
Answer accepted
Cristian Rosas [Tecnofor]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 11, 2018 • edited

Hi  Ronen,

I haven't tested it. Put this in a post-function in the creation in the first place and use a store post function (out of the box) just in case it doesn't work:

import com.atlassian.jira.component.ComponentAccessor

def projectComponentManager = ComponentAccessor.getProjectComponentManager()

def component1 = projectComponentManager.findByComponentNameCaseInSensitive('component name')
def component2 = projectComponentManager.findByComponentNameCaseInSensitive('component name')
// whatever you need


if (issue.issueType.name == 'issuetype name') {
    issue.setComponent(component1)
} else if (issue.issueType.name == 'issuetype name') {
    issue.setComponent(component2)
}
// whatever you need

Tell us if it worked!

Hi Cristian,

I tested and it works!

Thanks so much.

though I do have another question.

I am trying to assign 2 components to 1 issue type:

if (issue.issueType.name == 'issuetype name') {
    issue.setComponent(component1)
    issue.setComponent(component2)

but only the second one is being added (because I believe it setComponent)

do you know how I can add another component? maybe:

issue.setComponent(component1, component2)

thanks,

Ronen

Cristian Rosas [Tecnofor]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 13, 2018

It works as a collection, so you need to add the value in the same variable. Try something like this:

def collection1 = projectComponentManager.findByComponentNameCaseInSensitive('component name')
collection1.add(projectComponentManager.findByComponentNameCaseInSensitive('component name'))

I think it should be enough.

tested and failed, but with a little research I was able to debug:

def collection1 = projectComponentManager.findByComponentNameCaseInSensitive('component name')
collection1.addAll(projectComponentManager.findByComponentNameCaseInSensitive('component name'))

"addAll" resolved the issue

Tested successfully!!!

Thank you so much Cristian - big help!

Hi, Could I use this code if I wanted to base the Component on an issue summary?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events