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,559,302
Community Members
 
Community Events
184
Community Groups

Cannot set component of issue in a ScriptRunner post-function

Amir Katz (Outseer)
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.
May 31, 2018

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():

foo.png

 

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? 

3 answers

1 vote
Amir Katz (Outseer)
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.
Jun 26, 2018

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])
}
0 votes
Amir Katz (Outseer)
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.
May 31, 2018

Here's a reference post:

https://community.atlassian.com/t5/Answers-Developer-Questions/Post-function-groovy-search-summary-and-according-to-keywords/qaq-p/502061

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

0 votes
Moses Thomas
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 31, 2018
Amir Katz (Outseer)
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.
May 31, 2018

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):

bar.png

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events