Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner - Can I update Custom Field options and sort them alphabetically?

I am looking to use ScriptRunner to query all organisations within a SD and iterate through those values to add them to a new Custom Field. I seem to be able to query the orgs and have a large list.

A single item in the list would be: [CustomerOrganizationImpl{id=5, name=ShortName - LongName}]

I would like to take each one from the list and add to a Custom Field named, for example, "Reporting Organisation". The format of the option would be "ShortName (5) LongName". After each org is added as an option for the Custom Field I would like to sort them.

Is that possible with ScriptRunner? The only examples I have seen are related to modifying issues rather than the Custom Field values themselves.

1 answer

1 accepted


I believe it is possible by calling sortOptionsByValue method. Here is an example where you can test in the Script Console:

import com.atlassian.jira.issue.fields.config.manager.FieldConfigManager
import com.atlassian.jira.component.ComponentAccessor

final customFieldName = "Select List"

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects().findByName(customFieldName)
def fieldConfig = ComponentAccessor.getComponent(FieldConfigManager).getFieldConfig(10209)

  • Replace "Select List" with your custom field name.
  • Replace 10209 with your field config ID.

To quickly retrieve field config ID, you can navigate to Administration > Fields > Custom fields > Configure > Edit Options. Then look at the URL for 'fieldConfigId=', please refer to the screenshot below:

Screenshot 2021-06-30 at 11.32.26 AM.png

I hope this helps! :D


Hi Helmy,

Thanks for your help with the sort. That was a tiny piece of the puzzle but led me to the right sources for the other pieces. I am writing a script to query all Organizations. I then take those organizations and add them as options to another custom field with the ID appended to the name of the option. The script will compare the custom field options to the Organizations and determine by the ID if the option needs renaming or if a new organization needs adding to the list. The sort happens at the end. I added it as a nightly cron job and it seems to work; I just need to iron out any bugs. 

We were previously doing this through the html using os_username and os_password to authenticate but the latest Jira updates have disabled that functionality and we weren't too keen on re-enabling it. Perhaps this info will help someone else who is looking for a similar solution to be aware it is possible with ScriptRunner.

Glad to know it worked out for you. If I did help, please accept my answer :) 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

321 views 3 14
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you