How show fields base on drop down value?

Shah Baloch January 7, 2022

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

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Pramodh M
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 7, 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

Shah Baloch January 10, 2022

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 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

Shah Baloch January 10, 2022

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.

Tim Perrault
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 13, 2022

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
Shah Baloch January 13, 2022

@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
TAGS
AUG Leaders

Atlassian Community Events