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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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