Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

Custom field filtering by value from another custom field, multi select required

Edited

@Nic Brough _Adaptavist_

@Jamie Echlin _Adaptavist_

I'm looking for javascript or another option (scriptrunner is installed), to allow filtering of custom field B based on custom field A values. I've tried Cascading selects and they don't work for me due to the multi select need on the second custom field.

Custom field B will filter based on the selection of A and allow a selection of multiple values.

A :

  • 1
    • B values:
      • A
      • B
      • C
  • 2
    • B values:
      • D
      • E
      • F
  • 3
    • B values:
      • G
      • H
      • I

Can anyone suggest a method to pull this off, without installing another plugin than scriptrunner?

A and B are required

these are mocked up in html, not as custom fields yet. 

If A:1 is selected, the user can select any combination of the A,B,C values from B. image.png

If A:2 is selected, the user can select any combination of the D, E, F values from B.

image.png

etc..

3 answers

1 accepted

1 vote
Answer accepted

Hi David,

The recommended approach via ScriptRunner would probably be to use Behaviours. You would want to set up a server-side script on the single-select field which restricts the multi-select field's options using setFieldOptions:

import com.atlassian.jira.component.ComponentAccessor

def singleSelect = getFieldById(fieldChanged)


def
 multiSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("CustomFieldB")
def msConfig = customField.getRelevantConfig(issueContext)
def msOptions = ComponentAccessor.optionsManager.getOptions(msConfig)

def filteredOptions = msOptions

switch (singleSelect.value) {
    case "1":
        filteredOptions = msOptions.findAll {it.value in ['A', 'B', 'C']}
        break

    case "2":
        filteredOptions = msOptions.findAll {it.value in ['D', 'E', 'F']}
        break
}

formField.setFieldOptions(filteredOptions)

Thanks! @Joanna Choules 

I'm setting up the Behaviour.

I changed customfield.getRelevant... to multiSelect.getRelevant...

and put an actual custom field name in our jira instance  in the getCustomFieldObjectByName("... call

Do I need to define formField as something?
I've tried switching it to multiSelect, but no avail there either. 

 

image.pngimage.png

Oh yes, sorry, you need to add a line to define a separate FormField for the multi-select:

def formMultiSelect = getFieldByName("CustomFieldB")

and then call setFieldOptions on that. 

@Joanna Choules Works perfectly! Thanks for your help!

@David Hightower  

It will be nice if you share your full code here.

 

I getting error on line "def multiSelect = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Alarm")"

 

Thanks,

 Amar

Hello everyone 

@Joanna Choules 

The code source it's fonctiannally , but i have a problem beacause when a i change the value for case for example i'm select "1" and after i select "2" the list does not update. 

Exist a function or other for fix this problem ?

For have a list updated when to change case

Thanks in advance :) 

Is it possible to create a new cascading select field to replace your existing fields? I use it and it works great for route problems to the appropriate support teams in our office.

cascadingSelect.png

@Michael Thompson with the Cascading select, I was limited to a single value selection in the second field. 

I need to be able to select 1 option in first field, then 1 to many in the second field. 

I haven't found a way to get Cascading selects to work for that goal yet. 

Ahh, I see. In that case this option will not cut it for you. Sorry!

Suggest an answer

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

Do you use Jira Cloud with Microsoft Teams?

Hi, Jira users! Do you use Jira alongside Microsoft Teams? We want to hear how you’ve used the power of Jira Cloud and Microsoft Teams (via the Jira Cloud for Microsoft Teams app) to achieve a team...

531 views 1 9
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