I am trying to implement one code to get a set of values listed in select list based on the value selected in a check box.
I have implemented the below code. But it is not working.
Can you please help me to investigate on this?
This is the code:
import com.onresolve.jira.groovy.user.FieldBehaviours import com.onresolve.jira.groovy.user.FormField import com.atlassian.jira.component.ComponentAccessor def customFieldManager = ComponentAccessor.getCustomFieldManager() def optionsManager = ComponentAccessor.getOptionsManager() FormField checkBox = getFieldById("customfield_20690") def selectList = getFieldById("customfield_13992") def customField = customFieldManager.getCustomFieldObject(selectList.getFieldId()) def config = customField.getRelevantConfig(getIssueContext()) def options = optionsManager.getOptions(config) def checkBoxVal = checkBox.getValue() if (checkBoxVal == "A") { def optionsMap = options.findAll { it.value in ["AB", "BC"] } .collectEntries { [(it.optionId.toString()): it.value] } selectList.setFieldOptions(optionsMap) } else if (checkBoxVal == "B") { def optionsMap = options.findAll { it.value in ["C", "D", "E"] } .collectEntries { [(it.optionId.toString()): it.value] } selectList.setFieldOptions(optionsMap) }
Another couple of thoughts:
1) Note that the setFieldOptions method can take a simple List of options; you shouldn't need to call .collectEntries at all. See https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/restricting-priority-and-resolution.html
2) Where are you implementing this? If it's in an initialiser, then the above code will run once when the create/edit page loads. If you want it to run every time your check box changes, then you need to implement it as a script on the checkbox field. A screenshot of your behaviour's configuration would be helpful.
Can you add some logging messages in there so you can see the intermediate values in the app log.
Also please use the {code} macro, it's unreadable otherwise.
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.