Sort custom field options using a script?

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 2, 2024

Does anyone know of a way to programmatically sort the options in a Select List custom field? It can be accomplished via the UI using the link indicated in this screenshot, but we programmatically add items to a couple of lists and would like to also be able to programmatically sort the lists after doing do. We use the OptionsManager interface, which offers several methods for managing lists, but none for sorting. Thanks!

jirascreenshot.JPG

2 answers

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 23, 2024

Thanks, Peter-Dave. Even better, I found a sortOptionsByValue() method in the Options class and am accomplishing the task as follows:

ComponentAccessor.getOptionsManager().getOptions(fieldConfig).sortOptionsByValue(null)

0 votes
Peter-Dave Sheehan
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 3, 2024

With the OptionsManager interface, you can retrieve the list of options, sort it in memory and adjust the sequence field for each option, then use "updateOptions()" to save the new sorted list.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events