You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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"
}
}
}
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.