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
myCustomField.setFieldOptions(myCustomFieldMap)
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!
@Nic Brough -Adaptavist- thoughts?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.