Hello everyone!
How do you think, is it possible to split a cascading field into two fields, the first of which will be responsible for the parent value, and the second for its child? Both with drop-down lists?
Now I managed to make such a list only for the parent element. But I had difficulties when trying to make a field so that the child depends on the parent and displays only the necessary options.
Has anyone implemented similar examples?
Below is a script that displays the parent values of a cascading field.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.onresolve.scriptrunner.canned.jira.fields.model.PickerOption
def customField = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_ID_CASCADING")
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def config = customField.getConfigurationSchemes()*.oneAndOnlyConfig?.find()
if (!config) return []
def parentOptions = optionsManager.getOptions(config)?.findAll { it.parentOption == null && !it.disabled } ?: []
// Search
search = { String inputValue ->
parentOptions.findAll { it.value.toLowerCase().contains(inputValue?.toLowerCase() ?: "") }
.collect { [id: it.optionId.toString(), name: it.value] }
}
// Option
toOption = { Map item, Closure highlight ->
new PickerOption(
value: item.id,
label: item.name,
html: highlight(item.name, false)
)
}
getItemFromId = { String id ->
def opt = parentOptions.find { it.optionId.toString() == id }
if (!opt) return null
[id: opt.optionId.toString(), name: opt.value]
}
renderItemViewHtml = { Map item -> item.name }
renderItemTextOnlyValue = { Map item -> item.name }