Can I export all custom field options/values?

Script Runner has a "Bulk import custom field values" script built in.  I'm looking for a script or add-on or built in functionality to export all of the values/options for a custom field.  Specifically a Cascading Select List. I'd like to be able to export the whole thing to Excel or CSV, currently the only way I know to get this data is copy/paste from the browser and them cleaning it all up.

1 answer

1 accepted

1 votes

You can use something like this to print the option values with nesting. Should also work with multi-level cascading select.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option

def optionsManager = ComponentAccessor.getComponent(OptionsManager)

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("CascadingSelect") // <- change name of field

Closure formatOption
def sb = new StringBuilder()

formatOption = { int depth, Option option ->
    sb << (("\t" * depth) + option.value + "\n")
    depth++
    option.childOptions.each {
        formatOption(depth, it)
    }
}

cf.getConfigurationSchemes().each { fieldConfigScheme ->
    def fieldConfig = fieldConfigScheme.getOneAndOnlyConfig()
    sb << "Options for ${fieldConfigScheme.name}\n\n"

    optionsManager.getOptions(fieldConfig).each {
        formatOption(0, it)
    }
}

"<pre>" + sb.toString() + "</pre>"

That's very slick, thanks for the quick turnaround.  For a regular field it's perfect. For a Cascading Select, every option below the top level is indented further, so it makes for a very wide page.  But I should be able to manipulate in it excel a bit.  Thank you!

hrm it wasn't when I ran it, they were indented... maybe I screwed something up somehow.

You can just change the "depth++" to a 0 to turn off indenting.

That's the one.  Thank you!

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,755 views 11 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot