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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the easiest way to quickly test groovy script is to create script field and test it on actual issue without any consequences
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We all had to learn once ;-) Anyway, hopefully that sort of problem would come out in testing...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Jamie.
Two weeks ago I had no idea Groovy exists. Still learning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Alexey and Jamie, this will be very useful on the next project !
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.