Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Hide Custom Field Option Based on Another Custom Fields Options in Jira Dats center

Digvijay Singh Gehlot
Contributor
April 24, 2025

Hi Community, 

My use case is:

I want to hide "Yes" option under custom field X drop down when "No" option is selected in both custom fields: A and B. 

If "No" option is selected in custom field A and "Yes" option is selected in custom field B or vise-versa, or "Yes" option is selected in both custom fields: A and B then custom field X shows "Yes" option in the drop down.

Please guide on how we can achieve the above requirement using scriptrunner behavior in jira data center. Any sample code for reference would be a great help. 

Thanks

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
April 24, 2025

Hi @Digvijay Singh Gehlot

This is a very common question and my answers for this area available in the Community.

I have given a similar answer for this in this Community Post.

The only difference for your case is that instead of setting the field to required you need to filter the option in your field x when No is selected in fields A and B.

So similar to the Community Post link share above, you must create 2 Server-Side Behaviour configurations. One for Field A and one for Field B separately.

And each of the Behaviour configurations, you must do something like:-

For the Server-Side Behaviour configuration for List A:-

def listA = getFieldById(fieldChanged)
def listB = getFieldByName("List B")
def listX = getFieldByName("List X")

def listAValue = listA.value.toString()
def listBValue = listB.value.toString()

def options = ['Yes', 'No']

if(listAValue == "No" && listBValue == "No") {
options = ['No']
}

listX.setFieldOptions(options)

For the Server-Side Behaviour configuration for List B:-

def listB = getFieldById(fieldChanged)
def listA = getFieldByName("List A")
def listX = getFieldByName("List X")

def listAValue = listA.value.toString()
def listBValue = listB.value.toString()

def options = ['Yes', 'No']

if(listBValue == "Yes" && listAValue == "Yes") {
    options = ['No']
} 

listX.setFieldOptions(options)

Please note that the sample codes provided above are not 100% exact to your environment. Hence, you must make the required modifications.

I hope this helps to solve your issue. :)

I am looking forward to your feedback.

Thank you and Kind regards,
Ram

 

Digvijay Singh Gehlot
Contributor
April 27, 2025

Thank you so much @Ram Kumar Aravindakshan _Adaptavist_ for the above solution. It worked flawlessly. 

Few followup questions below:

Q1) What if there are two custom fields with same name? Is there a way to call two different custom fields by their Ids instead of their names in the above code?

Q2) What condition we should pass if we want to hide "Yes" option in List X drop-down when List A and/ or List B are set as "None"?

I am looking forward to hearing from you soon.

Thanks

TAGS
AUG Leaders

Atlassian Community Events