How do I add options to a Select List custom field programatically?

Javier Portillo
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.
March 25, 2012

Hi there,

I would like to know how to add default options to a custom select list programatically.

Thanks

7 answers

2 votes
Bernhard Gruenewaldt April 24, 2014

I wrote a plugin to add/remove/edit customfield values.

The plugin provides a REST API. It works from Jira 6.2+

1 vote
Radek Kantor
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.
March 25, 2012

Hi,

use OptionsManager createOption(FieldConfig fieldConfig, Long parentOptionId, Long sequence, String value)

http://docs.atlassian.com/software/jira/docs/api/latest/com/atlassian/jira/issue/customfields/manager/OptionsManager.html

Check thread: https://answers.atlassian.com/questions/16646/how-do-i-programatically-create-and-add-options-to-custom-fields-of-type-select-and-radiobutton

Use search option before asking new question. Add options to select list is so common issue, that it was already answered in the past.

Javier Portillo
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.
March 25, 2012

Sorry for repeating the question. Anyway, by using the precious link, I dont know how to set a value in a select field from a plugin. In the example is shown how to create an option but not how to select one of the previously created options.

Any help?

Radek Kantor
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.
March 26, 2012

Try use

issue.setCustomFieldValue

and as newValue parameter use on of the options from your select CF. I think, that this solution do not update change history tab. To update history use

customField.updateValue(fieldLayoutItem, issueObject, modifiedValue, changeHolder)

Some links:

https://answers.atlassian.com/questions/22527/how-to-set-a-select-list-type-custom-field-programably

http://forums.atlassian.com/thread.jspa?threadID=46940


Dmitry Miroshnichenko
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.
December 7, 2012
0 votes
Paul Stahlke August 27, 2020

I need this. In the meantime, I see it's available in Bob Swift's Command Line Interface plugin.

https://bobswift.atlassian.net/wiki/spaces/JCLI/pages/1294538018/addCustomFieldOptions

0 votes
Chase Whitener May 21, 2020

A year later. Any solution?

0 votes
Chase Whitener April 2, 2019

Is there still no solution to this problem in 2019?

Nathan Given June 11, 2019

I'm in the same boat, I'm using Jira Cloud and I have to sync 100 field options in my custom field select list with an outside system that changes every month.

 

I'd love to find out how to do this.

Brandon Robins November 14, 2019

@Nathan Given Did you ever figure out how to do this?

Nathan Given May 23, 2020

@Brandon Robins 

 

I abandoned the idea of a custom field and instead used components (since you can use the API to update components).

Not ideal, and definitely doesn't work in all cases. But it may be something you're also able to do.

0 votes
Bernhard Gruenewaldt August 19, 2014

UPDATE:

The current version of the Custom Field Editor Plugin (1.1+) supports cascading Fields and offers a REST API: https://marketplace.atlassian.com/plugins/jiracustomfieldeditorplugin

ITSupport August 19, 2014

Do you have ticket created so I can track this feature?! Thank you.

0 votes
ITSupport August 18, 2014

I was wondering if there is a way to programatically (REST API or other way) "add/remove/edit" parrent child options within CASCADE Custom Field?!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events