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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

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

2 votes
Answer 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

Atlassian Community Events