Getting issue component in postfunction

Charlie Misonne
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 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
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.
September 17, 2015
"myComponent" in issue.componentObjects*.name
1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 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
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.
September 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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 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
TAGS
AUG Leaders

Atlassian Community Events