How to show and hide custom field ​​based on the value of another field

niranjan March 13, 2024

Hello All,

we have two custom fields in our project one is Multi check box and "Other" was text filed.

When an option called "other" is checked then the custom field "Other" should show up with required. If any other option is selected then "Other" Custom field should be hide. 

 

Test Stage Required to Reset or Reboot ( check box field) - customfield_13639

Other (Text box field) - customfield_14801

Error.PNG

1 answer

0 votes
Matt Parks
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.
March 13, 2024

If you have Scriptrunner, you can create a relatively straightforward Behavior as follows. In this example, if the Microservice Type field is set to 'Other', the Microservice Other field is both visible and required. Otherwise, it is not.

def micServField = getFieldByName("Microservice Type")
def micOtherField = getFieldByName("Microservice Other")

def micServValue = micServField.getValue()

micOtherField.setHidden(true)
micOtherField.setRequired(false)

if (micServValue == "Other")
{
    micOtherField.setHidden(false)
    micOtherField.setRequired(true)
}

 

In this particular example, the Microservice Type field is a single-select list, so it would work in your environment only if Other is the only option selected. If you want the field to be visible if Other is selected along with other options, you'd want the if statement to look like this:

if (micServValue.toString().contains("Other"))

This is because the value of the multi-select list is actually an array of options.

Suggest an answer

Log in or Sign up to answer