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.