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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage
Highlighted

How do I programatically add options to custom fields of type select?

This was already posted in 2011 here:

https://community.atlassian.com/t5/Answers-Developer-Questions/How-do-I-programatically-create-and-add-options-to-custom-fields/qaq-p/483301

It took me quite a bit to get it running with Jira version 7.13.8.

Hope this helps someone

Here is the code:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.customfields.manager.*
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.customfields.option.*
import com.atlassian.jira.issue.fields.config.*

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_29100")
addOptionToCustomField(cField, "the new option")

private OptionsManager getOptionsManager() {
OptionsManager optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class);
return optionsManager;
}

public Option addOptionToCustomField(CustomField customField, String value) {
Option newOption = null;

if (customField != null) {
final List<FieldConfigScheme> schemes = customField.getConfigurationSchemes();
if (schemes != null && !schemes.isEmpty()) {
FieldConfigScheme sc = schemes.get(0);
Map configs = sc.getConfigsByConfig();
if (configs != null && !configs.isEmpty()) {
FieldConfig config = (FieldConfig) configs.keySet()
.iterator().next();

OptionsManager optionsManager = getOptionsManager();
Options l = optionsManager.getOptions(config);
Option opt;

newOption = optionsManager.createOption(config, null,
new Long(0), value);
}
}
}

return newOption;
}

 

0 comments

Comment

Log in or Sign up to comment
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you