Forums

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

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

Steve Hooczko
Contributor
August 26, 2024

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)?

2 answers

3 votes
Adriana Valentina Hernández Moreno
Contributor
August 26, 2024

Hello Steve, I'm Adriana Hernández from the ServiceRocket team.

By utilizing the Jira Cloud API 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
1 vote
Thomas Opiolka - codefortynine
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.
August 27, 2024

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," which allows you to use a CSV file as a data source. With the "Field Option 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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events