Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,359,801
Community Members
 
Community Events
168
Community Groups

How show fields base on drop down value?

Edited

I created a database picker field that has a value from one of the columns from the customer table in the database. I have multiple custom fields that I want to make hidden. The only time it should display those fields is if the user selects a value from the DB Picker field.

I would like to have those fields hidden all the time but whenever the user selects a value then those fields should be visible. I mean when it's empty fields should be hidden when there is a value then fields should be visible. I tried a behaviour script but it didn't display fields. Not sure what I'm doing wrong.

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours

def locationName = getFieldById('customfield_15401')
def cusName = getFieldById('customfield_18502')


cusName.setHidden(true)
if(locationName.value == ' ') {
cusName.setHidden(true)
}
else {
nameField.setHidden(false)
}

Thank you for your help

1 answer

1 accepted

0 votes
Answer accepted
Pramodh M Community Leader Jan 07, 2022

Hi @Shah Baloch 

def customField = getFieldById(getFieldChanged()).getValue().toString()
if ( customField == "optionValue"){
getFieldById("Custom field_10301").setHidden(true);
}

Can you try this code and let me know!!

Thanks,
Pramodh

Hi @Pramodh M thank you for your response. I'm having trouble understanding the code that you provided. I'm not sure where I can add my first DB picker field "customfield_15401" that its value can make another field "customfield_18502" visible.

I would like the second custom field to behave based on the first field's value. The second custom field should be hidden by default. If a customer selects a value from the DB picker field "customfield_15401" then the second field should become visible otherwise it should remain hidden.

My coding skills are limited. Can you please write the complete code for me? I appreciate your help.

Pramodh M Community Leader Jan 10, 2022

Hi @Shah Baloch 

Add the Behaviour to DB Picker field

and add the script below

In the optionValue place add the actual value in your DB Picker Field Option

def customField = getFieldById(getFieldChanged()).getValue().toString()
if ( customField == "optionValue"){
getFieldById("customfield_18502").setHidden(false);
}
else {
getFieldById("customfield_18502").setHidden(true);
}

 Let me know if you have any further queries

Thanks,
Pramodh

Thank you @Pramodh M  the DB Picket field contains more than 100 values options. Adding all values will cause issues maintaining the script. It is the location field, when the user is creating an issue if a user is reporting an issue about a specific location they will select one of the locations, once the value is selected then other fields should become visible otherwise hidden. Isn't there any other way to make it work without adding option values? I mean without adding option values in the script.

Thank you for your help.

Try this out. It just looks to see if there is a value in the the custom field. If the field does not have a value then the other field won't show.

def customField = getFieldById(getFieldChanged()).getValue()
if (customField){
getFieldById("customfield_18502").setHidden(false);
}
else {
getFieldById("customfield_18502").setHidden(true);
}
Like Shah Baloch likes this

@Tim Perraultthank you for your response. A team member reached out to the Adaptavist support and they helped us to make it work. Here is the working coding that we added in both the Initializer and Behaviour sections. Hope it can be helpful for others.


def userName = getFieldById('customfield_18507')
def numOfDevices = getFieldById('customfield_18504')

if (!userName.value) {
numOfDevices.setHidden(true)
}
else {
numOfDevices.setHidden(false)

}

 

Thanks

Like Tim Perrault likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

168 views 1 6
Read article

Atlassian Community Events