Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to hide custom fields when Version Picker is empty?

Diana
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
October 31, 2022

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

Suggest an answer

Log in or Sign up to answer
1 vote
Daniel Yelamos [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
January 17, 2018

You cannot do this. As we specified in the article that you are referencing to:

"This script hinges on the parentIssueId being present in the form. As such, you will need to associate the script with a visible field. It will not work as an initialiser."

You can see this as a warning in the article:

Screen Shot 2018-01-17 at 11.34.32.png

So to solve your issue all you have to do is not use it as an initialiser, since they are loaded before the form is populated.

If this solved your answer, please accept the answer so that other users know that this question has been solved.

May I help you further?

Cheers!

Dyelamos 

Yevgen Lasman
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
January 17, 2018

But how parentIssueId field is populated with its value? Is it like an internal name which is being auto-populated by JIRA one field with such name appears on a form?

Daniel Yelamos [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
January 17, 2018

I don't actually know how it works, since that is on JIRA's side. But think of it this way:

When the form is loaded, these things happen.

1. A request is sent.

2. Behaviours load.

3. Behaviours execute initialisers. 

4. Jira loads data into the form. This includes things like the project and such.

5. Rest of behaviours are executed.

6. Behaviours await triggers from the user.

So as you can see, the initialisers are loaded before the data of the server is parsed into the form. The problem is that parentIssueID is populated at step 4. Do you understand what I mean?

If this solved your answer, please accept the answer so that other users know that this question has been solved.

May I help you further?

Cheers!

Dyelamos

TAGS
AUG Leaders

Atlassian Community Events