Hide/show field depending on selected value

Hello,

 

We are using the Scriptrunner plugin via the Behaviours to show/hide fields based on the selected value on a radio button. We have noticed that this only works on the create screen and when updating the radio button field via "Edit" button on the edit screen. This is not working when we change the field value using the pencil icon. Is this the expected behaviour? Below is the added server side script on the radio button field:

 

import com.onresolve.jira.groovy.user.FormField

FormField fieldChangeDeliveryDatePostponed = getFieldById("customfield_10403")
FormField fieldRootCauseOfDeliveryPostponement = getFieldById("customfield_10169")
FormField fieldUpdatedReleaseDate = getFieldById("customfield_10514")

if (fieldChangeDeliveryDatePostponed.getFormValue() == "10520") { //Yes
fieldRootCauseOfDeliveryPostponement.setHidden(false)
fieldUpdatedReleaseDate.setHidden(false)
}
else {
fieldRootCauseOfDeliveryPostponement.setHidden(true)
fieldRootCauseOfDeliveryPostponement.setFormValue("-1")
fieldUpdatedReleaseDate.setHidden(true)
fieldUpdatedReleaseDate.setFormValue(null)
}

4 answers

1 accepted

Hi Lyka

The inline edit for fields that you use in a behaviour should be disabled. This means that if you have say, a choice list field that contains the value Other, and when Other is selected then some other field becomes hidden, you will need to add the "other" field to the behaviour even though it's not strictly needed. 

Screenshot.PNGAttached is the behavior.

Hi Lyka,

why don't you use dedicated plugin for it? On marketplace you can find Dynamic Forms and there is customfield Dynamic radio button. It works on create, edit, view and transition screen.You can show/hide fields and tabs based on the selected value.

 

Best Regards

This is nice for those running JIRA on-prem. It is not available for those running JIRA On-demand (Cloud).

Good day,

 

I'm also trying to hide/show fields based on selected value

Below is my code and is not working:

import com.onresolve.jira.groovy.user.FormField

FormField dropDown = getFieldById("customfield_10306")
FormField fconditionA = getFieldById("customfield_10510")
FormField conditionB = getFieldById("customfield_10515")

if (dropDownValue.getFormValue() == "High")

conditionA.setHidden(false)
conditionB.setHidden(true)

}
else
{
f conditionA.setHidden(true)
conditionB.setHidden(false)
}

 

using Adaptavist  ScriptRunner for Jira version 5.16

Jira Service Desk 3.6.1

Hello Nombulelo,

Not sure if your if condition is a typo, you haven't declared the "dropDownValue". Should it be "dropDown"? Also the "f conditionA" in your else statement has space.

Ooh sorry, below is the correct code:

 

import com.onresolve.jira.groovy.user.FormField

FormField dropDown = getFieldById("customfield_10306")
FormField conditionA = getFieldById("customfield_10510")
FormField conditionB = getFieldById("customfield_10515")

if (dropDown.getFormValue() == "high")

{

conditionA.setHidden(false)
conditionB.setHidden(true)

}
else
{
conditionA.setHidden(true)
conditionB.setHidden(false)
}

Ooh sorry, correct code. Anything wrong on the below?

import com.onresolve.jira.groovy.user.FormField

FormField dropDown = getFieldById("customfield_10306")
FormField conditionA = getFieldById("customfield_10510")
FormField conditionB = getFieldById("customfield_10515")

if (dropDown.getFormValue() == "high")

{

conditionA.setHidden(false)
conditionB.setHidden(true)

}
else
{
conditionA.setHidden(true)
conditionB.setHidden(false)
}

The code looks fine. Can you confirm that this serverside script is added on the dropDown field? Can you also try to use .getValue() instead of .getFormValue()? Please note of the case sensitivity of high/High. It should be same with the high value of the actual field.

Screenshot.PNGPlease see attached

So is the field for conditionA and conditionB are not shown/hidden when you try to modify the priority field?

Suggest an answer

Log in or Join to answer
Community showcase
Emilee Spencer
Published yesterday in Marketplace Apps

Marketplace Spotlight: DeepAffects

Hello Atlassian Community! My name is Emilee, and I’m a Product Marketing Manager for the Marketplace team. Starting with this post, I'm kicking off a monthly series of Spotlights to highlight Ma...

37 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot