I have about 400 values that I'd like to add as options to a custom field (ideally a 'Select List- Single Choice). Is there a way I can import these options or do I have to manually add them all?
400 options! Yow.
If you have the ScriptRunner add-on installed, you could script it. I've done similar and can provide a bit of guidance if you do have it.
-Payne
Hi @Payne
could you please help me here. i am looking for the similar requirement. i have script runner installed.
My Requirement: Read 4 options from CSV in to HEADER (select list) and 400 options to SUB-HEADER (select list). Based on the option selected in HEADER, the corresponding options should be visible in the SUB-HEADER Custom Field (Not all 400).
eg. Options in HEADER are A,B,C,D.
if i select A, the SUB-HEADER should have (A1,A2,A3,.........A100).
if i select B, the SUB-HEADER should have (B1,B2,B3,.........B100).
similarly for C and D.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is a basic script that will populate a single choice list; it can be run from the script console. I have not programmatically populated a linked list like you describe, so I can't offer any suggestions there. But, maybe the basic approach here will be of use to you.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.fields.config.FieldConfig
import com.atlassian.jira.issue.fields.config.FieldConfigScheme
import com.atlassian.jira.issue.fields.CustomField
CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Toppings")[0];
List<String> values = ["Pepperoni","Sausage","Onions"]
if (customField != null) {
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 = ComponentAccessor.getOptionsManager();
Options options;
int nextSequence;
for(int i=0;i<values.size();i++)
{
options = optionsManager.getOptions(config);
nextSequence = options.isEmpty() ? 1 : options.getRootOptions().size() + 1;
optionsManager.createOption(config, null, (long) nextSequence, values[i]);
}
}
}
}
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.