Behaviours plugin filter select list values based on project selection on issue creation

Todd Winton November 22, 2015

I'm using the behaviors plugin.  I have figured out how to filter the values of a select list.  However, I need to filter this list based on project selection during issue creation.

Script I am using:

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def formField = getFieldByName("Location - NA") 
def customField = customFieldManager.getCustomFieldObject(formField.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def optionsMap = options.findAll {
    it.value in ["Kansas City", "Bejing", "Memphis"] 
}.collectEntries {
    [
        (it.optionId.toString()) : it.value
    ]
}
formField.setFieldOptions(optionsMap)

2 answers

1 vote
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 24, 2015

I would switch on:

getIssueContext().getProjectObject()

which should give you a Project... IIRC initialisers fire when the project changes, so that might be a good place to put it. Mikey's answer should work too I think.

0 votes
MikeyS
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 22, 2015

Generally speaking, I would use your behaviour on the Project field if that is the controlling factor.

  • Go to Your Behavior -> Fields -> Add -> "Project"
  • For the Project field listing, "Add serverside script"

You should then be able to get the value of the project using something like:

projectValue = getFieldById(getFieldChanged()).getValue

Note that I have not actually tested that code.

Once you have the project value you can use if/else statements or a switch statement to set the appropriate field options for the corresponding projects.

Suggest an answer

Log in or Sign up to answer