How to display a custom field's options based on another custom field value ?

Oğuzhan Kırlangıç October 24, 2019

I have 2 select list ( single choice ) custom fields.

Custom Field1 is countries i.e  Germany,France,Italy

Custom Field2 is cities    i.e.  Köln,Berlin,Paris,Monaco,Milano,Roma

I want to display only Milano and Roma when Custom field 1 is selected as Italy.

I do not use Cascaded Custom Fields, these two fields are distinct.

How can I do that, probably with Scriptrunner Behaviors ?

Thanks in advance !

 

2 answers

0 votes
PVS
Banned
October 24, 2019

This Is the code Can You Try This Is Working Script Behaviour 

 

 

 

import com.atlassian.jira.component.ComponentAccessor
def storeName = getFieldByName("Store Name")
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObject(storeName.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
if (getFieldById(getFieldChanged()).getValue()!=null){
String val=getFieldById(getFieldChanged()).getValue() as String

switch(val){

case"7":
def optionToSelect = options.findAll { it.value in ["HAMDAN STREET STORE"] }
storeName.setFormValue("HAMDAN STREET STORE")
storeName.setFieldOptions(optionToSelect)
break
case"9":
def optionToSelect = options.findAll { it.value in ["AL AIN STORE"] }
storeName.setFormValue("AL AIN STORE")
storeName.setFieldOptions(optionToSelect)
break

}}

0 votes
PVS
Banned
October 24, 2019

HI @Oğuzhan Kırlangıç 

I think you should create a scripted field for Custom field 2 for reflecting the changes depends on custom field 1

eg.


1 ) Download Script Runner Plug in.
2 ) Create a "Scripted Field" Custom field
3) Go to Admin >> Script Field>> Edit the custom field which you have
recently created.
4 ) Below is an example which select the value from select custom field and
push it the same to Scripted field.

eg code : -

here I am returning the value of Select custom field to sctipted field.


def select = getCustomFieldValue("Select")
if (select) {
return select
}
else {
return null
}

// This script return the value which you have selected in Select custom field, instead you can

// redefine the code as per your requirement.

 

Cheers

PVS

Suggest an answer

Log in or Sign up to answer