Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,780
Community Members
 
Community Events
184
Community Groups

How to hide custom fields when Version Picker is empty?

Edited

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? 

1 answer

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 31, 2022

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!

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 31, 2022

Ah yes, nice catch on my typo.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events