Hello,
We have a Behavior (scriptrunner) that shows only certain values in a select list field when certain other values are chosen in a different select list field:
Here is the script:
def RespProject = getFieldByName("Responsible Project")
def AgileTeam = getFieldByName("Agile Team")
def customField = customFieldManager.getCustomFieldObject(AgileTeam.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
if (RespProject.getValue() as String == "FC Audio") {
def optionsMap = options.findAll {
it.value in ["VSP", "VST", "Aud_Decibels", "None"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
AgileTeam.setFieldOptions(optionsMap)
}
else if (RespProject.getValue() as String == "FC Connectivity") {
def optionsMap = options.findAll {
it.value in ["DCON_Fermi", "None"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
AgileTeam.setFieldOptions(optionsMap)
}
However, I cannot make it still allow the selection of the "None" option. It automatically selects the first value in the list, and sometimes we just want to have a value selected in "Responsible project", but the "Agile Team" can still be empty, until an analysis is made.
Thank you!
"None" is not really an "option", but if you add either [null: "None"] or ["-1": "None"] to your optionsMap it should work. Basically, try
AgileTeam.setFieldOptions(optionsMap + ["-1": "None"] )
I do a similar thing in a Behaviour and add a key/value pair of empty strings, i.e. ["":""]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For me, on Jira 7.9.2 and Scriptrunner 6.3.0, I got a 'static type checking' error by following the above example.
I solved the error by type-casting the added Option, like so:
accountType.setFieldOptions(selectAvailableOptions + (Option) ["-1": "None"])
Added import statement:
import com.atlassian.jira.issue.customfields.option.Option
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I tested all your options specially the + (Option) ["-1": "None"] and i got the following error on JIRA 8.13:
Is there any other way to do it?
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '{-1=None}' with class 'java.util.LinkedHashMap' to class 'com.atlassian.jira.issue.customfields.option.Option' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.atlassian.jira.issue.customfields.option.Option(LinkedHashMap)
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.