Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to get the count of items chosen in a select field

Donald Kelley
December 7, 2015

trying to take a field that has a list of customers and be able to query for only issues where the number of customers is greater than 1. The field will also have null values at times

1 answer

0 votes
Vasiliy Zverev
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 Champions.
December 10, 2015

Try using multiuser picker field to store list of customers and calculated field (provided by ScriptRunner) with this script to store it count

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField

/**
 * Get number of users for multiuser picker
 */
CustomField multiuserCstFld = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("FieldName")
if (multiuserCstFld == null)
    return "custom field not found"

return "" + ((ArrayList) multiuserCstFld.getValue(issue)).size()
Silvia Goljerova
December 28, 2018

I've tried this on the 'Components' field and receive an error:

"custom field not found"

Does this not work on OOTB fields?

Vasiliy Zverev
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 Champions.
January 1, 2019

Components is not a custom field.

You should method of Issue class use https://docs.atlassian.com/software/jira/docs/api/7.1.2/com/atlassian/jira/issue/Issue.html#getComponents-- 

Like # people like this
Silvia Goljerova
January 2, 2019

Thank you!

Christopher Gronde
Contributor
December 20, 2019

So what would this look like in order to have a field that showed the number of components?  Since it's not a custom field?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events