Number of options selected in multi-choice field via JQL

JQL:

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.

Script:
How can I get the number of options selected for a multi-select custom field via Script.

2 answers

1 vote
Henning Tietgens Community Champion Jan 21, 2014

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.

Got the same request, have to count the choosen options of a multi-select field. Created a scripted field and added your code, but seems to be not working?!

Any ideas?

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.

 

0 votes

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

  • List all the issues that belong to team X
  • List all the issues that belong to team Y
  • List all the issues that belong to team X AND Y
  • List all the issues that belong to team X OR Y

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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

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...

24,959 views 2 7
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