Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to change the options listed in Component/s based on selection from a Custom field

Frantisek Kust April 22, 2020

Hi Team,

I am looking if possible to create a dependency between a Custom field and Component/s field.

Both are single select list.

-> The custom field has 3 values (e.g Product A, Product B, and Product C).

Once I will select Product A, the Component/s list will be restricted to only valid options for this Product.

Could be this achieved using the Behaviours plugin?
Or another approach like Listener?

I found there a very similar request, just Component determining Custom field with code as below, but I would need to revert it and don't know how. :-(

{code}

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.project.component.ProjectComponent

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def selectList1 = getFieldById(fieldChanged)
def selectList2 = getFieldByName("Sub-component")

def selectList1Val = selectList1.getValue()
Map fieldOptions = [:]
fieldOptions.put ("-1", "None")

selectList1Val.each{
def selectListname = it.getAt("name")

switch (selectListname){
case "Comp 1" :fieldOptions.putAll (["22601":"Sub1", "22602":"Sub2", "22603":"Sample Sub 3"])
break
case "Comp 2" :fieldOptions.putAll (["22604":"Sample Sub 1", "22605":"Sub 2 sample"])
break
}

}
selectList2.setFieldOptions (fieldOptions)

{/code}

 

Could be anyone so nice and help me with, pls?

Many thanks in advance,

Frank

1 answer

0 votes
Michelle Pogado August 6, 2020

I have the same question.
The SriptRunner Library only has recipes for custom select lists, but nothing for Component/s field.

Suggest an answer

Log in or Sign up to answer