Forums

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

When someone choose one option from single select list then in few option should be visible

Sonal Sharma August 7, 2022

I have two single select dropdown menu custom field called

Custom field one= Product ( I have 9 options under this list)

Custom field two= Component

So now when someone select Infrastructure from Product then in Component List I want to see the following options; Automation, testing, developing, other.

 

I am using behavior from script runner but it seems not to be working for me.

Can you please guide me with this?

1 answer

0 votes
Antoine Berry
Community Champion
August 8, 2022

Hello @Sonal Sharma ,

Please create a behaviours and link it to the Product field, and use this script (please update the custom fields ids) : 

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor


def optionsManager = ComponentAccessor.getOptionsManager()
def productId = 11001
def componentId = 11002


def productField = getFieldById("customfield_"+productId)
def productFieldValue = productField.getValue()

def componentField = getFieldById("customfield_"+componentId)

def component = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(componentId)

def componentConfig = component.getRelevantConfig(getIssueContext())
def componentOptions = optionsManager.getOptions(componentConfig).findAll { !it.getDisabled() }

def componentList = ["Automation","testing","developing","others"]
def componentsOptionsMap = componentOptions.findAll()

if ((productFieldValue == "Infrastructure") || ("Infrastructure" in productFieldValue)){
componentsOptionsMap = componentOptions.findAll{ it.value in componentList }
}

componentField.setFieldOptions(componentsOptionsMap)

Let me know if that works.

Antoine Berry
Community Champion
August 10, 2022

Hello @Sonal Sharma ,

Have you been able to try this script ?

Sonal Sharma September 20, 2022

@Antoine Berry Thanks for the support but it is not working for me, I don't see any changes in the behavior. 

Antoine Berry
Community Champion
September 21, 2022

@Sonal Sharma Could you find anything in the logs ?

Suggest an answer

Log in or Sign up to answer