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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner Behaviours: change select list based on another select list option

Hello,

I have two select lists, Outcomes and Indicators.

Each Outcome and Indicator in the two select lists begine with a series of numbers. 

There are over 100 indicator options, however, only specific indicators relate to a specific Outcome. 

Example would be that 1 Outcome  can relate to 1 Indicator  or 1.1 Indicator or 1.2 Indicator

I'd like to some how filter the results in the Indicator select list based on the Outcome, running off the series of numbers that comes in the beginning of the value. 

If 1 Outcome, only list the matching potential Indicators.

I'm assuming I'll want to accomplish this with ScriptRunner 

 

2 answers

Create a behaviour on the Outcomes field. This behaviour will change the available options of the Indicators select list every time the Outcomes select list changes. Use the following server-side script:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager

def outcomeField = getFieldById(fieldChanged)
def indicatorsField = getFieldByName("Indicators")

// Get the all the options of Indicators
def indicatorsCF = customFieldManager.getCustomFieldObjectsByName("Indicators")[0]
def config = indicatorsCF.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)

if (outcomeField.value == "1.0") {
def newOptions = options.findAll { it.value in ["option1", "option2"] }
indicatorsField.setFieldOptions(newOptions)
} else if ((outcomeField.value == "2.0")) {
def newOptions = options.findAll { it.value in ["option3", "option4", "option5"] }
indicatorsField.setFieldOptions(newOptions)
}

Change "1.0" and "option1", "option2", etc. to whatever the names of your options are. You can add more "else if" as you need to. 

Hi Roland,

Thanks for this, however, I have 75 Outcomes and 130+ indicators, Outcomes may be 1.0, 1.1, 1.2, etc and Indicators may be 1.1.1, 1.1.2, 1.1.3, etc. 

I was looking for a solution that would not require me to hand coded each outcome and indicator into the script. 

Might this be accomplished through a regular expression? 

If user selected Outcome 1.1, then only show Indicators that match on 1.1.*

You could do something like this. It would eliminate the need for hardcoding all the Indicators, but you would still need to hardcode the Outcomes. It would more or less be copy-pasting the else if and changing the two numbers.

if (outcomeField.value == "1.0") {
def newOptions = options.findAll { it.value.startsWith("1.0") }
indicatorsField.setFieldOptions(newOptions)
} else if ((outcomeField.value == "1.1")) {
def newOptions = options.findAll { it.value.startsWith("1.1") }
indicatorsField.setFieldOptions(newOptions)
}

 

Thanks @Roland Holban _Adaptavist_  !
But how to not only show value in a multiple select list, but select/highlight these values please ?

How to write something like below? I want to show all options but a few selected ones.

options.findAll { it.value NOT in

Hi, 

You can use every function like this:

options.findAll { it.every{ it != 'Your option to avoid'} }

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you