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.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
duh, i got it wrong - please try: https://gist.github.com/jechlin/f951aff26dd83197cba1e88b66683a6d
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
how would you modify the above, if you only wanted to display/export enabled values.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@JamieA Sorry for my ignorance, but I miss these points:
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Amir Katz (Outseer) I'm not Jamie but I can help. This code is executed in the ScriptRunner addon.
If you have it installed, you can run this via the Script Console. It can be found in:
Administration > Add-ons > Script Runner (on the side toolbar) > Script Console
The output is visible below the script field, under the "Logs" tab.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Daniel Brown Thanks, works great!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@JamieAYou saved me a ton of typing! Thank you very much!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.