Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Make a filed Hide depending on another field using JIRA

navya k
Contributor
October 6, 2019

I have 3 custom fields namely: Fruit[Apple, Mango], Apple, Mango

In my view screen, I would like to show the fields based on the Fruit user selected.

Ex: if a user selects Apple -> only Apply field should be visible and hide the Mango field and vice-versa. 

How can I achieve this?

 

I tried using the "Behaviour" plugin, but it doesn't work on the View screen.

3 answers

2 votes
Anzar Khan October 6, 2019

Hi Navya K,

Behaviours don't work on the view screen. They only function on the Create/Edit screens and the other screens mentioned here. On the view screen, any field with a behaviour on it will simply open an Edit window when clicked, as explained in the documentation. 

You can do this via "Behaviours" in ScriptRunner. You just have to add this script on the Fruit custom field.

def fruit =getFieldByName("Fruit")
def fruitVal = fruit.getFormValue() as List
def mango = getFieldByName("Mango")
def apple = getFieldByName("Apple")
apple.setHidden(true)
mango.setHidden(true)
if(fruitVal.get(0)=="Apple"){
apple.setHidden(false)
}
else if(fruitVal.get(0)=="Mango"){
mango.setHidden(false)
}
else{
log.error"---Value of fruit"+fruitVal
}

 

navya k
Contributor
October 6, 2019

@Anzar Khan 

Is there any way we can hide it on view screen?

Like Anzar Khan likes this
Anzar Khan October 6, 2019

Hi Navya,

I don't think this will be possible on the view screen.

Thanks and regards,

Anzar

0 votes
Robin Flood
Contributor
October 7, 2019

Hello Navya!

Why don't you just have a multi select field, like checkboxes or something, named "Fruit" and provide "Apple" and "Mango" as the alternatives. Only the options chosen will be displayed in the view screen anyway.

I probably don't understand what you're trying to achieve, like what are the fields called "Apple" and "Mango" contain?

Feel free to explain it to me and I'll do my best to help! 

navya k
Contributor
October 7, 2019

I'm trying to compare my scenario with this example, let me know if you didn't understand it.

We have 1 custom field called "Object type" which will have multiple options like Fruit, Veg, Animals. And also we have created the one web panel which should contain fields depending on the Object type. Refer :

sample.PNG

Ex: If the user selects "Fruit", the web panel should show only fruit-related custom fields. If the Object type is "Veg", panel should show only Vegetable related fields and so on. 

Like Anzar Khan likes this
Robin Flood
Contributor
October 7, 2019

Ahh I see. Maybe you can define the issue type based on the fruit alternatives instead? Like create 2 custom issue types "Apple" and "Mango", that would allow you to connect different screens containing different fields based on the selection.

If that's not an option you can also use a post function to populate the relevant fields with a default value which should make them visible on your view screen.

For example if you have 2 fields called "Colour" and "Taste" that should only be shown in your other tab if "Apple" is chosen in you multi field, the post function could give those 2 fields default values like "Colour: choose apple colour" and "Taste: choose apple taste". 

If those suggestions don't fit, please give me an example case of how the whole process looks like from your end, and I'll give it another try :) 

0 votes
Tushar.Kamble
Contributor
October 6, 2019

Hi Navya,

 

This can be achievable using "Behaviour" app which comes with script runner.

 

~Tushar

navya k
Contributor
October 6, 2019

@Tushar.Kamble 

I tried that one only. it works only on create/edit screen. 

I have default values in my fields like Apple[Yes], Mango[Yes]. Fruit[Apple]

I added the below script on Fruit field

def objectType = getFieldByName("Fruit").getValue();

def apple = getFieldByName("Apple");
def mango = getFieldByName("Mango");

if (objectType == "Apple") {
mango.setHidden(true)
}

 

During issue creation time, my fields are changing according to the Fruit value. But if I open the issue, it shows all the fields :

Fruit: Apple

Apple: Yes

Mango: Yes

Suggest an answer

Log in or Sign up to answer