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,364,116
Community Members
 
Community Events
168
Community Groups

Is it possible to change field options based on another field?

Working on a project and have a unique request that I can't seem to figure out if it's possible or not. 

 

The team has a static master list of documents that are required based on a country choice. 

 

For example, the master list has 5 documents, but for Country A only 2 of those documents are required, but for Country B all 5 documents are required. 

 

They would like a checklist of those documents to be changed based on the country choice so if you were to select Country A, the document checklist column would only show 3 choices, but if you were to select Country B, all 10 would be displayed.

 

ConditionalFieldValues.png

Is this possible in JIRA? Happy to purchase a 3rd party add-on to make it possible as well. I looked into Dynamic Forms but I believe this can only show/hide entire fields, not values within a field.

 

Thanks for any help! :) 

 

6 answers

1 accepted

0 votes
Answer accepted

The sample code to get this working is as follows:

This requirement is achievable using Behaviour feature. You may refer to our sample code in the library about Dynamic Select.

Based on the sample, I configured the server side script for the "Country", which will trigger every time the value change:

import com.atlassian.jira.component.ComponentAccessor

def country = getFieldById(getFieldChanged())
def countryValue = country.getValue() as String

def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def checkboxes = getFieldByName("Checkboxes")
def customField = customFieldManager.getCustomFieldObjectsByName("Checkboxes")[0]
def fieldConfig = customField.getRelevantConfig(getIssueContext())
def fieldOptions = optionsManager.getOptions(fieldConfig)

def optionUS = [ 'Option 1', 'Option 2', 'Option 3' ]
def optionUK = [ 'Option 2', 'Option 3' ]

switch (countryValue) {
    case "US - United States":
        checkboxes.setFieldOptions(fieldOptions.findAll {it.value in optionUS})
        break
    case "UK - United Kingdom":
        checkboxes.setFieldOptions(fieldOptions.findAll {it.value in optionUK})
        break
}
3 votes

@Kevin Ultsh

 

Check out ScriptRunner for Jira. This plugin has functionality called Behaviors which can be used to accomplish what you want.

Got this working with Script Runner. Thanks all!

Craig Nodwell Community Leader Aug 31, 2022

Nice. 

Nice job! If you want to post the code, others may find the answer and be helped!

1 vote
Craig Nodwell Community Leader Aug 26, 2022

Hi @Kevin Ultsh fully agree with @Kian Stack Mumo Systems Scriptrunner is the way to go here.  Behaviors will do exactly this, and it's only a part of the add-on. 

0 votes

Hey @Kevin Ultsh there is help on using Behaviours here: https://docs.adaptavist.com/sr4js/latest/features/behaviours 

This is one of the common use cases for Scriptrunner behaviours. It would be good to get your feedback on setting it up.

@Craig Nodwell @Kian Stack Mumo Systems We actually have Script Runner and I looked into Behaviors but wasn't sure if it was possible to hide/show values of a field, or just hide/show entire fields. I will review it again. Thanks for the heads up.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS

Atlassian Community Events