Number of options selected in multi-choice field via 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.

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

2 answers

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
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

950 views 3 9
Read article

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