Forums

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

How to get unused the options of custom field

xu zhijian May 3, 2012

Hi All,

I want to find which options of one custom field are not used by issues , and i get one function is like "issue Object getCustomFieldValue(CustomField customField)", Do we have any other way to fetch the unused options besides to search in all issues ?

1 answer

1 accepted

1 vote
Answer accepted
Dieter
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.
May 3, 2012
You would have to loop through the options and for each option you can get the list of issues having this option value using this method

http://docs.atlassian.com/software/jira/docs/api/latest/com/atlassian/jira/issue/customfields/impl/MultiSelectCFType.html#getIssueIdsWithValue(com.atlassian.jira.issue.fields.CustomField,%20com.atlassian.jira.issue.customfields.option.Option)

This could be faster than looping through the issues and calling getCustomFieldValue if you don't have so many options but a large number of issues

Dieter
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.
May 3, 2012
The method is defined in interface http://docs.atlassian.com/software/jira/docs/api/latest/com/atlassian/jira/issue/customfields/MultipleSettableCustomFieldType.html

Please check the link which custom field types implement it

xu zhijian May 3, 2012

thanks for your information .

xu zhijian May 9, 2012

Hi Dieter, I'm wondering how to create a MultipleSettableCustomFieldType Object to call the mothod "getIssueIdsWithValue", when i use

MultipleSettableCustomFieldType mc = (MultipleSettableCustomFieldType)ComponentManager.getComponentInstanceOfType(MultipleSettableCustomFieldType.class);

for(Option op : opt)
{
  if (mc.getIssueIdsWithValue(cf,op).isEmpty())
   unusedOpt.add(op);		   
}

"mc.getIssueIdsWithValue(cf,op).isEmpty() " will cause a java.lang.NullPointerException. Thanks .


xu zhijian May 9, 2012

I've found the solution like this :

CustomField cf = getCustomField();

CustomFieldType cft = cf.getCustomFieldType();

final MultipleSettableCustomFieldType mc = (MultipleSettableCustomFieldType) cft;

anyway .thanks very much .

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events