Query Regarding Script for field

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)
}

2 answers

This widget could not be displayed.

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.

This widget could not be displayed.

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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

203 views 1 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you