You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
This was already posted in 2011 here:
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;
}