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

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Can't change select list options based on Issue Type using Scriptrunner Initializers Edited

I'm trying to code some Scriptrunner initializers that will change the drop-down options for a specific custom field (single select drop-down) depending on the issue type selected.

To start, I've created a couple of behaviors that are mapped to individual issue-types within the same project, and I'm working on coding up an initializer for each that will populate the drop-down list with the values I require.

Currently, my code looks like this:

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()

def myCustomField = getFieldById("19103")
def myCustomFieldCF = customFieldManager.getCustomFieldObject("customfield_" + myCustomField.getFieldId());
def myCustomFieldConfig = myCustomFieldCF.getRelevantConfig(getIssueContext());
def myCustomOptions = optionsManager.getOptions(myCustomFieldConfig);

def myCustomFieldMap = myCustomOptions.findAll {
it.value in ["filtereOption1", "filtereOption2", "filtereOption6", "filtereOption9"]
}.collectEntries {
[(it.optionId.toString()): it.value]
} //assuming 10 pre-defined options - I only want to show these 4



But I continually find that my custom field is displaying the full list of pre-defined options, rather than the sub-list that I'm defining above.

Through logging, I can see that the options map is being created properly.  It appears that the method call myCustomField.setFieldOptions(myCustomFieldMap) is failing (though I haven't been able to capture it in my logs yet).

I'm wondering if the error could be in how I'm configuring the custom field itself, or the behavior.

Any help would be appreciated!

1 answer

Suggest an answer

Log in or Sign up to answer

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