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.
Community moderators have prevented the ability to post new answers.
I've found the solution:
CustomField cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("MyCustomField"); Options options = ComponentAccessor.getOptionsManager().getOptions(cf.getConfigurationSchemes().listIterator().next().getOneAndOnlyConfig());
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. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This works really well Mladen B. But based on this i have a similar requirement. How can i achieve this for nfeed custom field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It works fine. But do you know how to get options of Parent & Child Option of Cascading List
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I believe you're wrong. See the example of the working code that I've discovered that is working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
But does it work with multiple custom field contexts and different set of options for different projects and/or issue types?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please read the question description more carefuly. I don't have neither projects nor issues in my JIRA. Only custom field created.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
issue is null in my case. There are no issues created, nor projects.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.