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

This widget could not be displayed.

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

This widget could not be displayed.

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

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

106 views 2 0
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