Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Cannot set component of issue in a ScriptRunner post-function

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

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])
}

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

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

93 views 0 5
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you