groovyjirascriptrunner-for-jira

How to get a list of all the options for a CustomField in an issue (Jira)?


I'm trying to write a Jira script that would copy an issue from one project into another, while also using the same CustomField value. The problem is, that the customField values and options are project-specific, so it isn't a trivial task of setting the new issue's customField to the same value.

I can get an issue by it's key and I can get it's customField value, but I can find no way of finding every possible value for a customField of an issue for a given project. I've tried adapting this script: https://library.adaptavist.com/entity/update-single-select-custom-field

,but the availableOptions will always remain empty.


Solution

  • To obtain the options information from a custom field, you can use the following snippet:

    def optionsManager = ComponentAccessor.optionsManager
    def customField = ComponentAccessor.customFieldManager.getCustomFieldObject(<customfield_id>)
    def fieldConfig = customFieldB.getRelevantConfig(<issue>)
    def options = optionsManager.getOptions(fieldConfig)
    

    I hope that helps. Thanks, Ivan.