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

Kevin Ultsh August 26, 2022

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
Kevin Ultsh September 12, 2022

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
Kian Stack Mumo Systems
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 26, 2022

@Kevin Ultsh

 

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

1 vote
Kevin Ultsh August 31, 2022

Got this working with Script Runner. Thanks all!

Craig Nodwell
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 31, 2022

Nice. 

Kian Stack Mumo Systems
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 6, 2022

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

Kevin Ultsh September 12, 2022

Will do!

1 vote
Craig Nodwell
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 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
Warren Da Costa August 30, 2022

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.

0 votes
Kevin Ultsh August 26, 2022

@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