Scriptrunner - Getting Value of First Component

I'm very new to Jira API, Groovy scripting and the Scriptrunner Plugin. Given that, I have been able to use it in a post function to raise a custom notification event based on the value of a custom field. Now a customer would like to be able notify different groups of users based on the component entered. Team A should be notified if Component A is entered, Team B notified when Component B is entered, ect. The event raised should be base on the first component entered and in this project the user should only chose one component for an issue.

My question is - Using scriptrunner plugin, is it possible to get the value of the first component entered and if so can anyone provide an example of the script?

If this is not possible, I can always remove components and implement a customfield with the required values, but would have to change some filters and dashboards as well.

Thanks in Advance

2 answers

1 accepted

3 votes
Accepted answer

I'm not sure if getComponentObjects() method returns components in same order as user added, but you can test with code like this

issue.getComponentObjects() { c ->
   //do whaever you want with...
   log.debug "Component ${c.getName()}"


issue.getComponentObjects().getAt(0)?.getName() //corrected per Jamie's comment. Now null safe

Thanks Alexey, I'll give this a try. FYI - I was able to get around this by using by component lead assignment. I raised a custom event by checking the value of issue's assignee for the various component lead names.

the easiest way to quickly test groovy script is to create script field and test it on actual issue without any consequences

Should be the following, otherwise you will get NPE for issues with no components.


Creating a script field for testing is a good idea, you don't need to assign it to any issues. Or personally I just use issuemanager to get an issue, and test in the admin script panel.

We all had to learn once ;-) Anyway, hopefully that sort of problem would come out in testing...

Thanks Jamie.

Two weeks ago I had no idea Groovy exists. Still learning

Thanks Alexey and Jamie, this will be very useful on the next project !

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,266 views 5 10
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