How can I add multiple drop down selections to a custom field at one time (e.g., import)?
Asked by Steve Hooczko:

I have created a single selection custom drop down field and want to import a long list of available selections into JIRA for this field without having to do them one at a time (e.g., country names)?


Answers:
author: Adriana Valentina Hern?ndez Moreno
body: Hello Steve, I'm Adriana Hern?ndez from the ServiceRocket team.

By utilizing the Jira Cloud [API](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-custom-field-options/#api-rest-api-3-field-fieldid-context-contextid-option-post) alongside Python3, it is possible to add new values to a select list custom field in Jira through the use of a CSV file.

Please see the Python3 script below as an example:  

```
import requests

from requests.auth import HTTPBasicAuth

import json

import csv

#variables for the url

jiraInstance = "YOUR_INSTANCE_NAME" #name (the name that goes before .atlassian.net)

fieldId = "customfield_0000"

contextId = "0000" #ConfigSchemeId=

auth = HTTPBasicAuth("YOUR_EMAIL", "YOUR_TOKEN")

headers = {

"Accept": "application/json",

"Content-Type": "application/json"

}

#List

options_create = []

options = []

#CSV route

file = '/Users/YOUR_USER/Desktop/YOUR_FILE.csv' #here goes the path to the CSV that contains the options, e.g., my file is in the desktop.

def getoptions():

with open(file) as file_obj:

heading = next(file_obj) #skip headers in csv.

reader_obj = csv.reader(file_obj) #with this function we can read and manage the csv. 

for row in reader_obj:

options_create.append(row[0]) #creating a list with the option entries of the row 0.

options_unique = list(set(options_create)) #Local variable to get unique option values.

for option in options_unique: #go trough each 'option' value on the option_unique list.

headers = {

"Accept": "application/json",

"Content-Type": "application/json"

 }

url = f"https://{jiraInstance}.atlassian.net/rest/api/3/field/{fieldId}/context/{contextId}/option"

payload = json.dumps({

"options": [{

"value": option

 }]})

response = requests.request(

"POST",

url,

data=payload,

headers=headers,

auth=auth

 )

print(response.status_code)

getoptions()
```

I hope this helps!  
Best Regards,  
Adriana Hern?ndez


author: Thomas Opiolka
body: Hi Steve,

You might consider using a third-party plugin for the import task. If you only need to import values once, remember that you don't have to keep the plugin installed afterward. One such plugin is "[External Data for Jira Fields](https://marketplace.atlassian.com/apps/1219994/external-data-for-jira-fields?hosting=cloud&tab=overview)," which allows you to use a [CSV file](https://documentation.codefortynine.com/external-data-for-jira-fields/file) as a data source. With the "[Field Option Sync](https://documentation.codefortynine.com/external-data-for-jira-fields/field-options-sync)" configuration, you can sync values from the CSV into a native Jira select-list field either once or continuously if the file changes often.

After uninstalling the app, the field options synced will remain intact, making it technically a one-time import. I should disclose that I am involved with the vendor of this app, but it remains a technically free option.

I hope this helps.

Thomas


Tags: cloud

jira-cloud