Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

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
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

95 views 0 5
Read article

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