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 Join to answer
Community showcase
Teodora [Botron]
Published Feb 15, 2018 in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

1,231 views 6 19
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot