Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Bulk importing/adding options to a select list custom field

Mark Bowden
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 22, 2019

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?

1 answer

0 votes
Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 22, 2019

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

Yaswanth April 17, 2020

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.

Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 20, 2020

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]);
      }
    }
  }
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events