Query Regarding Script for field

Parvathy December 15, 2016

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 votes
Jonny Carter
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 21, 2016

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.

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 15, 2016

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events