Number of options selected in multi-choice field via JQL

Peter T
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2014

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

2 votes
Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 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.

Hans-Hermann Hunfeld March 4, 2016

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?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 4, 2016

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
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 21, 2014

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.

Peter T
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2014

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