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

0 vote

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.

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

81 views 0 5
Read article

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