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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,307
Community Members
 
Community Events
185
Community Groups

Attempting to hide options in a select list based off of what is selected in another select list

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)

 

1 answer

@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)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events