Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to get all the Options of one CustomField (Select List)?

MB
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.
August 13, 2013

I have no projects created in my JIRA and I have no issues also. I have created one CustomField of type "Select List" and have set some options for that custom field. How can I get the list of all those options for that custom field from within JIRA plugin?

So far, I only found this method to retrieve all the Options of a (multi options) Custom Field:

CustomField cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(MY_CUSTOMFIELD_NAME);
Options options = cf.getOptions(key, jiraContextNode));

which requires jiraContextNode that I don't know how to acquire. There is also "ComponentAccessor.getOptionsManager()" but I don't know which method can be used...

My goal is really simple. To retrieve all the options of a given Custom Field, that's all.

Thanks in advance.

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

18 votes
Answer accepted
MB
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.
August 18, 2013

I've found the solution:

CustomField cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("MyCustomField");
Options options = ComponentAccessor.getOptionsManager().getOptions(cf.getConfigurationSchemes().listIterator().next().getOneAndOnlyConfig());

JPB June 19, 2014

Thanks Mladen, you saved my day.

That was what I needed, the options without project and issue, I didn't know how to adquire the jiraContextNode, but what you did works for me. :)

CCP TechOps December 22, 2014

@Mladen B: I have a requirement to export options of one custom field. How do i get the list using above code. Kindly let me know where i need to apply it.

Jayashree Shetty
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.
March 23, 2015

This works really well Mladen B. But based on this i have a similar requirement. How can i achieve this for nfeed custom field?

CST JIRA Confluence Admin July 18, 2016

It works fine. But do you know how to get options of Parent & Child Option of Cascading List

Joe Jadamec January 22, 2018

CustomFieldManager cFM = ComponentAccessor.getCustomFieldManager();
CustomField cf = cFM.getCustomFieldObject(fieldId); //your custom field id (Long)
OptionsManager optionsManager = ComponentAccessor.getOptionsManager();
com.atlassian.jira.issue.context.IssueContextImpl issueContext = new com.atlassian.jira.issue.context.IssueContextImpl(issue.getProjectId(), issue.getIssueTypeId());
FieldConfig fieldConfig = cf.getRelevantConfig(issueContext);
Options options = optionsManager.getOptions(fieldConfig);
for (Option option in options.getRootOptions()){
String parentOptionValue = option.getValue();
//do something with parentOptionValue
List<Option> childOptions = option.getChildOptions();
for(Option childOption in childOptions){
String childOptionValue = childOption.getValue();
//do something with childOptionValue
}
}

Like Leonard Chew likes this
2 votes
Florin Manaila
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.
August 13, 2013

Without the issue or at least project and issue type you can't, since one select list custom field can have different available options depending on project/issue type.

MB
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.
August 18, 2013

I believe you're wrong. See the example of the working code that I've discovered that is working.

Florin Manaila
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.
August 18, 2013

But does it work with multiple custom field contexts and different set of options for different projects and/or issue types?

MB
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.
August 18, 2013

I haven't found an option to define a different set of options for different contexts/schemes so far, so I'm not quite sure how will that influence an existing list of options for a given custom field. Is it possible to define different set of options for a single custom field at all in JIRA?

Florin Manaila
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.
August 18, 2013

Though custom field contexts have their limitations, they do allow you to create multiple sets of options for a single custom field. See this guide here:

https://confluence.atlassian.com/display/JIRA/Configuring+a+Custom+Field#ConfiguringaCustomField-configure

MB
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.
August 18, 2013

Oh, that's great :)

I checked out that link and I think this sentence explains why the code above works:
"Each custom field has a context named "Default Configuration Scheme for ..." which was created automatically by JIRA when you initially added your custom field."

I believe that "getConfigurationSchemes().listIterator().next()" returns that Default Configuration Scheme, thus providing the options that were given, when the custom field was first created, which was the subject of this question :)

+1 for the link :) Thanks :)

CCP TechOps December 22, 2014

I have a requirement to export options of one single select custom field. How do I get the list using above code. Kindly let me know where I need to apply it.

2 votes
RambanamP
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.
August 13, 2013

try with this

CustomField cf = ComponentManager.getInstance().getCustomFieldManager().getCustomFieldObjectByName(MY_CUSTOMFIELD_NAME);
FieldConfig cfC = cf.getRelevantConfig(new IssueContextImpl(project, issueType));

But you still need to know the "context" (project and issue type) of the option list.
You could iterate custom field configs (cf.getConfigurationSchemes())

check here to how get "jiraContextNode"

https://bitbucket.org/atlassian/jiraconnect-jiraplugin/src/379a84581bdb/src/main/java/com/atlassian/jconnect/jira/customfields/CustomFieldSchemeHelper.java

MB
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.
August 18, 2013

Please read the question description more carefuly. I don't have neither projects nor issues in my JIRA. Only custom field created.

2 votes
RambanamP
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.
August 13, 2013

try with following code to get all options

CustomField cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(MY_CUSTOMFIELD_NAME);
IssueContextImpl issueContext = new IssueContextImpl(issue.getProjectObject(), issue.getIssueTypeObject());
FieldConfig fieldConfig = cf.getRelevantConfig(issueContext);
OptionsManager optionsManager = (OptionsManager) ComponentManager.getComponentInstanceOfType(OptionsManager.class);
Options options=optionsManager.getOptions(fieldConfig);

MB
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.
August 13, 2013

issue is null in my case. There are no issues created, nor projects.

Joe Jadamec January 22, 2018

nevermind, see above

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events