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

Getting issue component in postfunction

Charlie Misonne Community Leader Sep 17, 2015

I'm writing a postfunction in the "create issue" workflow step with the ScriptRunner plugin

The script should check if the issue has a specific component named "myComponent" and returns true in order to fire an event


I tried this:

issue.component = "myComponent"

Too simple apparently. So I looked in the documentation and tried this in the Script Console:

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssue("JIRA-001")

For each issue key I try with the component appears to be `null`

[timespent:null, timeoriginalestimate:null, project:10022, description:null, type:6, resolution:null, number:24404, security:null, resolutiondate:null, fixfor:null, id:67268, key:null, summary:2nd test wit component, watches:1, creator:test-charlie, created:2015-09-18 09:50:15.0, reporter:test-charlie, priority:3, environment:null, component:null, timeestimate:null, duedate:null, votes:0, assignee:otheruser, updated:2015-09-18 09:50:15.0, workflowId:88798, status:1]


What am I missing?

I also tried getComponentObjects()


2 answers

1 accepted

"myComponent" in issue.componentObjects*.name
1 vote

Components is a multiple option field, which can have none, one, or many settings. 

You're finding "component: null" as a hangover from code from when the component was a single select, so you should ignore that.

Use issue.getComponentObjects() to get a collection of values. 

This is where my java/groovy lets me down - I don't know if there's an easy way to say "is the string 'My Component' represented by a projectComponent in this collection?" directly. 

What will work is brute force - iterate over the result and look at the names -

collectionOfComponents.each { if it.getName().equals('My Component') then {...} }

Will do it if you want to compare on component name.

the spread-dot operator is your friend here, componentObjects*.name returns a new List by calling getName on each object.

Charlie Misonne Community Leader Sep 20, 2015

Thanks for telling me what that 'component' attribute was ;) I tried both approaches and they work. The notation from Jamie seems the way to go Also: I was using get getIssue() instead of getIssueObject() in the script console which is deprecated

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published Apr 03, 2019 in Marketplace Apps

How to estimate projects more accurately?

Gaining insight into your team’s effectiveness and choosing the right estimation technique.   Estimating projects is hard. It is because people have the tendency to underestimate the time thin...

278 views 2 8
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