It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

1 vote
Answer 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 Sign up to answer
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

1,099 views 7 0
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you