For example I have a multi-choice field called Team nad I want via JQL to see all the Issue that are marked to impact more than one team. Writing an explicit querry (Teams = Team1 and Teams = Team2) is not an option as if I have 4 teams the possible combinations are 11.
How can I get the number of options selected for a multi-select custom field via Script.
You can create a scripted field
return ((getCustomFieldValue(10090)?.size())?:0) as Double
to get the number of selected values for customfield 10090. Use Number template and searcher. After creating the field you have to reindex all issues.
Than you can use this field to find all issues with scripted_field > 2.
The code is a couple of years old, but should still work. I'd break it down using a test issue - in the script-runner scripted field definition, there's a "preview" option, so you should use that to build up the query and see where it goes wrong.
i.e. try these (with the output type set to string)
return getCustomFieldValue (10090)
return getCustomFieldValue (10090).size()
Then add back the ? stuff - that's there to prevent errors when the field is empty or not valid for the issue.
JQL is not SQL. JQL finds issues that match criteria, it has nothing to do with the output.
So, you can use it to say
and so-on. Note that those human-language questions say absolutely nothing about the issue data that comes back, the counters of results or anything else. The answers from JQL are just issues that match the question.
If you have 11 combinations, you're going to need 11 queries to pull them out, and then you can push them through assorted gadgets or reports that might do the sums for you.
I suspect the best you can do is a derived field of some sort (with a bit of code) - something that shows the number of selected options, and maybe concatenates them together so you can interrogate it as unique strings.
I was not interested in the output but just a list of issues similar to any JQL where selected options are > 2
What do you mean by derived field? A scripted field (add-on scripts) or just a numeric hidden field that shows the number of options selected. I prefer the latter but I can't keep the cound up-to date as I can put easily logic to udpate that field on Edit.
Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...
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!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG