How to limit component based on selection in another field? (Two tier component)

Taylor Johnson February 14, 2020

Hello,

 

I am aware of the subcomponents plug in. What I'm looking for is two fields next to each other. The field on the left would be a category, and based on that selection, the component field would then have its options limited to a subset. 

 

 

Basically I want a way to make my components two tiered, but nothing more. The Subcomponent plug in is a bit too complex for what I want to do. I don't need folders or things like that and I don't want the field itself to have so much complexity. I just want to give my users one field to select from a few categories, then once that is selected, they can then choose a relevant component. 

2 answers

1 accepted

1 vote
Answer accepted
Thilo Brause
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.
June 8, 2020

You should be able to solve your problem by combining a Scriptrunner-Behaviour like here to identify the selected value with the description there how to limit the available components

Thilo Brause
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.
June 8, 2020

Take a look at:

import com.onresolve.jira.groovy.user.FieldBehaviours
import static com.atlassian.jira.issue.IssueFieldConstants.*
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.project.component.*
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def components = projectComponentManager.findAllForProject(issueContext.projectObject.id)
def cfManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager

final singleSelectName = 'System'
def formSingleSelect = getFieldByName(singleSelectName)
def singleSelectValue = formSingleSelect?.value

getFieldById(COMPONENTS).setFieldOptions(components.findAll { it.getName()?.contains(singleSelectValue.toString()) })

-----------------------

The above behavior (set to listen on the custom field "System") will limit the available components to the ones, where the name matches the value of the selected Systems.

Taylor Johnson June 8, 2020

Very nice! I'll see if we can try to implement this. We just started using ScriptRunner. Thank you! 

1 vote
Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 14, 2020

Hi @Taylor Johnson,

Welcome to the Atlassian Community.

Have you considered using the Select List (cascading) custom field instead of component?

Taylor Johnson February 15, 2020

I want to maintain the benefits component gives me like having component lead assigned and the component based dashboard gadgets. 

 

I've seen this done at my old company, I just don't know how.

Suggest an answer

Log in or Sign up to answer