Created
September 2, 2015 19:00
-
-
Save jechlin/8a0f026ac62091b553be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FormField formComponent = getFieldById(fieldChanged) | |
FormField formSubcomponent = getFieldByName("Subcomponent") | |
Object componentFormValue = formComponent.getFormValue() | |
List componentIds = [] | |
if (componentFormValue instanceof List) { | |
componentIds.addAll(componentFormValue as List) | |
} | |
else { | |
// could be an empty string if all components are deselected | |
if (componentFormValue) { | |
componentIds.add(componentFormValue) | |
} | |
} | |
Map fieldOptions = [:] | |
// fieldOptions.put("-1", "None") | |
def customField = customFieldManager.getCustomFieldObject(formSubcomponent.getFieldId()) | |
def config = customField.getRelevantConfig(getIssueContext()) | |
def options = optionsManager.getOptions(config) | |
def optionIdByName = [:] | |
options.each { | |
optionIdByName.put(it.value, it.optionId.toString()) | |
} | |
componentIds.each { componentId -> | |
try { | |
Long.parseLong(componentId as String) | |
} catch (NumberFormatException e) { | |
log.error("Could not get component Id as Long") | |
return | |
} | |
def component = getProjectComponent(Long.parseLong(componentId as String)) | |
log.debug "name: \"" + component?.name + "\"" | |
switch (component?.name) { | |
case "Comp1": | |
fieldOptions.putAll([(optionIdByName["Lemons"]): "Lemons", (optionIdByName["Oranges"]): "Oranges"]) | |
break | |
case "Comp2": | |
fieldOptions.putAll([(optionIdByName["Spinach"]): "Spinach", (optionIdByName["Celery"]): "Celery"]) | |
break | |
} | |
} | |
log.debug("Will set fieldOptions: $fieldOptions") | |
formSubcomponent.setFieldOptions(fieldOptions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment