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
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Roland Holban (Adaptavist) !
But how to not only show value in a multiple select list, but select/highlight these values please ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How would this work if the options were asset (insight) objects? I know that you can established reference asset object custom fields, however if I hypothetically wanted to control this behaviour in a ScriptRunner field behaviour, is it possible?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How to write something like below? I want to show all options but a few selected ones.
options.findAll { it.value NOT in
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You can use every function like this:
options.findAll { it.every{ it != 'Your option to avoid'} }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.