Hello All,
I have some business requirements where they have requested two multiselect list fields in Jira and the behavior they have requested like
If multiselect field A has options 1,2,3,4,5, and Multiselect Field B has option A, B, C, D, E
then their requirement is if they have chosen the Option 1 in the field A then option A should visible in the Field B and if they have selected option 2 then option B should visible and so on but if they selected option 1,2 then A,B both should come and if they selected all options (1,2,3,4,5) then all options (A,B,C,D,E) should come in the field B.
Can somebody help me on the same? How can I set the same behavior in the script runner?
Thanks,
Shubhanshu
For your requirement, you need to configure a Server-Side Behaviour for the Multi-Select field that you wish to trigger the filtration for the second Multi-Select field.
Below is a working sample code for your reference:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def multi1 = getFieldById(fieldChanged)
def multi1Value = multi1.value as List
def multi2 = getFieldByName('Multi Select 2')
def options1 = ['1':'A','2':'B','3':'C','4':'D','5':'E']
def selectedOptions = []
multi1Value.each {
selectedOptions.add(options1.get(it))
}
if (multi1Value != [null] && selectedOptions.size() > 0) {
multi2.setFieldOptions(selectedOptions)
}
Please note the sample code provided is not 100% exact to your environment. Hence you will need to make the required modifications.
Below is a print screen of the Behaviour configuration for your reference:-
I also include a few test screens for your reference:-
In this example, I use two Multi-Select fields, i.e. Multi Select 1 and Multi Select 2. The Server-Side Behaviour has been configured for the Multi Select 1 field.
Hence, when the options are selected in the Multi Select 1 field, the options will be filtered accordingly in the Multi Select 2 field.
1. When the issue is being created, and no selection is made from the first Multi-Select field, all the options in the second Multi-Select field are also visible as shown in the image below:-
2. Once the options are selected in the Multi Select 1 field, the options in the Multi Select 2 field will be filtered accordingly, as shown in the images below:-
3. The same also applies when multiple options are selected from the Multi Select 1 field, i.e. accordingly, multiple options will also be displayed in the Multi Select 2 field as shown in the image below:-
I hope this helps to answer your question. :)
Thank you and Kind Regards,
Ram
Hello @Ram Kumar Aravindakshan _Adaptavist_ ,
Thanks for the script. It worked fine.
but I need one more help, how can I define the multiple options here?
For example, if I selected option 1 in the first multi list and want A, D option in the second list means mapping with the first field to second field is one to many.
Let me explain more about here
Custom Field | Values | |||
Multi Select Field A | 1 | 2 | 3 | 4 |
Multi Select Field B | A | D | G | J |
B | E | H | K | |
C | F | I | L |
Thanks,
Shubhanshu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you want to display multiple options on the second multi-select list based on the single option selected from the first multi-select list, you will need to use a condition like:-
if (multi1Value == ['1']) {
selectedOptions.add(options1.get('1'))
selectedOptions.add(options1.get('2'))
selectedOptions.add(options1.get('3'))
} else if(multi1Value == ['2']) {
selectedOptions.add(options1.get('4'))
selectedOptions.add(options1.get('5'))
}
Below is the updated code for your reference:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def multi1 = getFieldById(fieldChanged)
def multi1Value = multi1.value as List
def multi2 = getFieldByName('Multi Select 2')
def options1 = ['1':'A', '2':'B', '3':'C', '4':'D', '5':'E']
def selectedOptions = []
if (multi1Value == ['1']) {
selectedOptions.add(options1.get('1'))
selectedOptions.add(options1.get('2'))
selectedOptions.add(options1.get('3'))
} else if(multi1Value == ['2']) {
selectedOptions.add(options1.get('4'))
selectedOptions.add(options1.get('5'))
}
if (multi1Value != [null] && selectedOptions.size() > 0) {
multi2.setFieldOptions(selectedOptions)
}
Please note the sample code above is not 100% exact to your environment. Hence you will need to make the required modifications.
I hope this helps to solve your question. :)
Thank you and Kind Regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ @Shubhanshu Trivedi
Does this script work, i tried but its not working. I modified the field name, no compile error
But the dependent values are not shown.
I am getting null error for setFieldOptions()
Can you let me know if anything is missing or the process?
I'm using version 8.15* of Jira
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.