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

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()}"
}

or

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.

issue.getComponentObjects().getAt(0)?.getName()

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,760 views 11 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot