Hi all. Faced the problem of updating the options of the custom field of the cascading list. We have a third party system that contains a directory:
- Parent 1
-- child 1
-- child 2
- Parent 2
-- child 1
We update the custom field through the Scriptrunner, below is part of the update code.
def issue = ComponentAccessor.issueManager.getIssueObject('OTHER-205')
CustomField PROGRAM_FIELD_NAME = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_10244")
def om = ComponentAccessor.optionsManager
def options = om.getOptions(PROGRAM_FIELD_NAME.getRelevantConfig(issue))
def programs = Config.serviceDeskClient.sendGetRequest()
def temp = new HashMap<String, Program>(programs)
programs.entrySet().each {
def currentOption = options.find { op -> op.value.startsWith(it.key) }
if (currentOption.collect().size() == 1) {
currentOption.setValue(it.value.name)
it.value.subPrograms.each { sub ->
def currentChild = currentOption.childOptions.find { ch -> ch.value.startsWith(sub.key) }
if (currentChild.collect().size() == 1) {
currentChild.setValue(sub.value.name)
} else {
om.createOption(PROGRAM_FIELD_NAME.getRelevantConfig(issue), currentOption.optionId, (long) (currentOption.childOptions.size() + 1), sub.value.name)
}
}
} else {
om.createOption(PROGRAM_FIELD_NAME.getRelevantConfig(issue), null, (long) (options.childOptions.size() + 1), it.value.name)
}
}
om.updateOptions(options)
options.each {
log.error "${temp.containsKey(it.value.substring(0, 3)) && !Character.isDigit(it.value.substring(4, 5).charAt(0))}"
if (temp.containsKey(it.value.substring(0, 3))
&& !Character.isDigit(it.value.substring(4, 5).charAt(0))) {
it.childOptions.each { ch ->
if (!programs.get(it.value.substring(0, 3)).subPrograms.containsKey(ch.value.substring(0, 6))
|| !temp.get(it.value.substring(0, 3)).subPrograms.containsKey(ch.value.substring(0, 6))) {
om.disableOption(ch)
om.deleteOptionAndChildren(ch)
} else {
temp.get(it.value.substring(0, 3)).subPrograms.remove(ch.value.substring(0, 6))
log.error "Exception return"
return
}
}
} else {
log.error "DIASBLE OPTION ${it.value}"
om.disableOption(it)
om.deleteOptionAndChildren(it)
temp.remove(it.value.substring(0, 3))
}
}
om.updateOptions(options)As a result, we get the following picture.
1. In the general list of options, a new value. pic 2
2. In option edit mode, the old value. pic 3
3. In the "view" task, the old value. pic 4
4. In the task to "edit" the new value. pic 5
The database stores the old value. Tried to index task/project/full reindex. A full reindex returns the old value.
Maybe someone faced similar?