Hide/show field depending on selected value

lykaibernardo January 11, 2016

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

1 vote
Answer accepted
Thanos Batagiannis _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 Leaders.
January 12, 2016

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. 

1 vote
Nombulelo Zizi October 3, 2017

Screenshot.PNGAttached is the behavior.

0 votes
Nombulelo Zizi October 3, 2017

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

lykaibernardo October 3, 2017

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.

Nombulelo Zizi October 3, 2017

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)
}

Nombulelo Zizi October 3, 2017

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)
}

lykaibernardo October 3, 2017

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.

Nombulelo Zizi October 3, 2017

Screenshot.PNGPlease see attached

lykaibernardo October 3, 2017

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

0 votes
Daniel Bajrak
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 Leaders.
January 11, 2016

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

Terri Edney April 10, 2016

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

Suggest an answer

Log in or Sign up to answer