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

1 vote
Answer accepted
JamieA Sep 17, 2015
"myComponent" in issue.componentObjects*.name
1 vote
Nic Brough [Adaptavist] Community Leader Sep 17, 2015

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.

JamieA Sep 17, 2015

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 in Marketplace Apps & Integrations

Webinar invitation: Generate custom Jira Cloud PDF reports and exports

Jira may be a staple part of your workday, but your colleagues, customers, business partners or an auditor might need information presented in a different format, that is easy to access and read. And...

61 views 0 1
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