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.
Hi,
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) ComponentAccessor.getOptionsManager().getOptions(fieldConfig).sortOptionsByValue(null)
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:
I hope this helps! :D
Cheers,
Helmy
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad to know it worked out for you. If I did help, please accept my answer :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.