Hey there,
I'm working on a script that detects the field values and reacts accordingly, but I'm running into an issue where I can't accurately determine if a multi-list selection is equal to the default option, "None". The same is true even after selecting a different item, then clicking back to "None". I am able to get my code to react to the values selected otherwise.
The code is executing under the myVariable field. Any help is greatly appreciated - code below.
// I've tried all of the following and none of these work.
Your error is with
String myVariableValue = ( String ) TeleportField .getValue()
In my experience, it's never a good idea to perform this sort of type conversion in groovy.
A multi-select field should typically return an array. If you convert that to strings, it becomes complex to process it.
Let groovy do the work for you.
def myField = getFieldById("customfield_15201")
def myFieldValue = myField.value
if(!myFieldValue){
//the field is not populated, that could be because it returns one of the followin
if(myFieldValue == null){
log.info "field is null"
}
if(myFieldValue instanceof String){
log.info "field is an empty string"
}
if(myfieldValue instanceof List){
log.info "field is an empty array" //this is the only one that should output on a multi-select field
}
} else {
if(myfieldValue instanceof List){
//bonus, if you have values in your multi-select
myFieldValue.each{selectedOption->
log.info "label of the selected option is: $selectedOption"
}
//or if you want the optionIds
myfield.formValue.each{optionId->
log.info "id of the selected option is: $optionId"
}
}
}
Thanks, this helped me get to where I wanted to go.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.