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()
"myComponent" in issue.componentObjects*.name
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the spread-dot operator is your friend here, componentObjects*.name returns a new List by calling getName on each object.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.