Scriptrunner behaviour - Show Hide Field upon Multi Option Select

Annie Kemp January 4, 2019

Hello, 

 

I am trying to use a ScriptRunner behavior in order to hide an open text field, upon selecting various options from a single select list. Each option that you select gives a new single select list. The code that I am using is below. While the new single select list does show upon selection, the field that i want hidden remains visible. It worked fine when i only had the behaviour set on one option, but when I added the other options, it got wonky. This is my first go at this, and any help is greatly appreciated!

 

def 1stField = getFieldByName("Region") -- Single Select Field w/options
def 2ndField = getFieldByName("Market") -- Open Text Field I want hidden
def OptionAField = getFieldByName("OptionA") 
def OptionBField = getFieldByName("OptionB") 
def OptionCField = getFieldByName("OptionC")
def OptionDField = getFieldByName("OptionD")

def 1stField = 1stField.getValue() as String

if (1stField== "OptionA") {
OptionAField.setHidden(false)
2ndField.setHidden(true)
}
else {
OptionAField.setHidden(true)
2ndField.setHidden(false)
}
if (1stField == "OptionB") {
OptionBField.setHidden(false)
2ndField.setHidden(true)
}
else {
OptionBField.setHidden(true)
2ndField.setHidden(false)
}
if (1stField == "OptionC") {
OptionCField.setHidden(false)
2ndField.setHidden(true)
}
else {
OptionCField.setHidden(true)
2ndField.setHidden(false)
}
if (1stField== "OptionD") {
OptionDField.setHidden(false)
2ndField.setHidden(true)
}
else {
OptionDField.setHidden(true)
2ndField.setHidden(false)
}

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events