It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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

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

}}

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Jira Cloud for Google Sheets: Automatically Refresh Your Data!

Remember that time you realized it was possible to refresh your Jira data in Google sheets with just one click? What if we told you that you can now get the latest data with no clicks at all?! Zero! ...

7,370 views 33 29
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you