I have a list of apps that can be selected in a multi-select field, and based off of those selections I wanted to display relevant fields in a separate multi-select field. I was following along with the following post: https://community.atlassian.com/t5/Adaptavist-questions/ScriptRunner-Behaviours-change-select-list-based-on-customfield/qaq-p/788924 and made a good amount of progress, however I got stuck towards the end of the thread. Right now, I can see the behaviour attempting to run in my logs, however the functionality isn't working at all. I started receiving this error in my log after adding the very last line to set the fieldOptions to allowedOptions:
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
[interface java.lang.Iterable]
[interface java.util.Map]
at Script1.run(Script1.groovy:67)
Worth noting that allowedOptions is evaluating to null, even though I am selecting an option in the affectedApp custom field of the Create Issue screen
Below is my code :
import com.atlassian.jira.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.context.IssueContext
import com.atlassian.jira.issue.context.IssueContextImpl
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.customfields.*
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfigImpl
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def allowedOptions = null
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def affectedAppField = getFieldByName("OutageAffectedApp")
def affectedAppValue = affectedAppField.getValue()
def affectedFunctionField = getFieldByName("OutageAffectedFunctionality")
def affectedFunctionCF = customFieldManager.getCustomFieldObjectByName("OutageAffectedFunctionality")
def config = affectedFunctionCF.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
log.warn("Value set to " + affectedAppValue)
log.warn("Config set to " + config)
log.warn("Options set to " + options)
if (affectedAppValue.toString() == "App1")
{
allowedOptions = affectedFunctionField.setFieldOptions(options.findAll {
it.value in ["Option1" , "Option2", "Option3"]
})
}
else if (affectedAppValue.toString() == "App2")
{
allowedOptions = affectedFunctionField.setFieldOptions(options.findAll {
it.value in ["Option4", "Option5", "Option6"]
})
}
else if (affectedAppValue.toString() == "App3")
{
allowedOptions = affectedFunctionField.setFieldOptions(options.findAll {
it.value in ["Option7", "Option8", "Option9"]
})
}
log.warn("Allowed Options evaluates to " + allowedOptions)
affectedFunctionField.setFieldOptions(allowedOptions)
@adimuzio - I changed your code slightly, does this work?
import com.atlassian.jira.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.context.IssueContext
import com.atlassian.jira.issue.context.IssueContextImpl
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.customfields.*
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfigImpl
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
java.lang.Iterable allowedOptions = null
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def affectedAppField = getFieldByName("OutageAffectedApp")
def affectedAppValue = affectedAppField.getValue()
def affectedFunctionField = getFieldByName("OutageAffectedFunctionality")
def affectedFunctionCF = customFieldManager.getCustomFieldObjectByName("OutageAffectedFunctionality")
def config = affectedFunctionCF.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
log.warn("Value set to " + affectedAppValue)
log.warn("Config set to " + config)
log.warn("Options set to " + options)
if (affectedAppValue.toString() == "App1")
{
allowedOptions = options.findAll {
it.value in ["Option1" , "Option2", "Option3"]
}
}
else if (affectedAppValue.toString() == "App2")
{
allowedOptions = options.findAll {
it.value in ["Option4", "Option5", "Option6"]
}
}
else if (affectedAppValue.toString() == "App3")
{
allowedOptions = options.findAll {
it.value in ["Option7", "Option8", "Option9"]
}
}
log.warn("Allowed Options evaluates to " + allowedOptions)
affectedFunctionField.setFieldOptions(allowedOptions)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.