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.
I've used this trick for Behaviours so many times without fail, but for some reason I can't get it to work for a custom field Version Picker (single select).
If any option is selected for Version Picker, another custom field "Text Multi-line" appears.
But if Version Picker is empty, I want the text field to hide. I've tried variations:
def field = getFieldByName("Version Picker")
def fieldValue = field.getValue()
def text = getFieldByName("Text Multi-line")
if (fieldValue != null) {
text.setHidden(false)
}
if (!fieldValue) {
text.setHidden(false)
}
def fieldValue = field.getValue() as String
if (fieldValue != "Unknown") {
text.setHidden(false)
}
But none of them work. If Version Picker is null/Empty, then the text field needs to hide.
(Or in the case of this script logic: If Version Picker IS NOT null/empty (a value was selected), then Text field IS NOT hidden.)
Does anyone know what I'm missing?
I like to use the helptext for debugging behaviours
Add this to your script:
field.setHelpText("$fieldValue (${fieldValue.getClass() - ${(fieldValue instanceof List) ? fieldValue[0].getClass() : ''})")
This will give you some clues as to what kind of data you are dealing with for each situation.
This should show you that when the version field is empty, a empty string value is returned. When one or more version is selected, you get a list of "VersionImpl" objects.
So armed with this information, you should be able to adjust your script accordingly.
def field = getFieldByName("Version Picker")
def fieldValue = field.getValue()
def text = getFieldByName("Text Multi-line")
text.setHidden(!fieldValue || fieldValue.first().name != 'Unknown')
hi @Peter-Dave Sheehan thank you for the quick response, and the debugging trick is neat!
I added a } between () and - because nothing was showing up at first.
field.setHelpText("$fieldValue (${fieldValue.getClass()} - ${(fieldValue instanceof List) ? fieldValue[0].getClass() : ''})")
I end up going back to the logic "if version picker is empty, then hide text field" and this is what I end up that worked for me
def field = getFieldByName("Version Picker")
def fieldValue = field.getValue()
def text = getFieldByName("Text Multi-line")
text.setHidden(fieldValue.toList().first() == null)
Thanks again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah yes, nice catch on my typo.
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.