Skip to content

Instantly share code, notes, and snippets.

@jechlin-adaptavist
Created May 6, 2020 14:54
Show Gist options
  • Save jechlin-adaptavist/bc452172e50ef21f68ddd1cc0073f661 to your computer and use it in GitHub Desktop.
Save jechlin-adaptavist/bc452172e50ef21f68ddd1cc0073f661 to your computer and use it in GitHub Desktop.
package examples
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def foodField = getFieldById(getFieldChanged())
def subFoodField = getFieldByName('Sub-Food')
def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager
def customField = customFieldManager.getCustomFieldObjectByName('Sub-Food')
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def newFieldOptions = []
if (foodField.value == [null]) {
subFoodField.setFormValue([]).setHidden(true)
} else {
subFoodField.setHidden(false)
}
if ('Fruits' in foodField.value) {
newFieldOptions.addAll(options.findAll { it.value in ['Apples', 'Bananas', 'Oranges'] })
}
if ('Vegetables' in foodField.value) {
newFieldOptions.addAll(options.findAll { it.value in ['Spinach', 'Cabbage', 'Cauliflower'] })
}
subFoodField.setFieldOptions(newFieldOptions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment