I have 3 Select List (single choice) custom fields. I want to set the available options of the fields in 2 & 3 depending on the selection of field 1. To test this, in the Initialize script of the behaviour I am able to set debug messages on the field 2 and 3 using setHelpText, but when I use setFieldOptions, the available options do not change. Any ideas?
Thank you @Fadoua and @Ram Kumar Aravindakshan _Adaptavist_ I found the problem. I didn't realized that all the possible options for fields 2 and 3 had to exist for it to work. I am sorry about that.
Once I set all the defaults possible in fields 2 and 3, it worked.
For example:
Believe me I was about to ask you if you had the options already added or are you trying to add them through the script.
Glad it worked at the end! Yes ScriptRunner is very vast and there is a lot to learn in it.
If you have any questions please don't hesitate to ask
Best of luck!
Fadoua
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your code shouldn't be in the initializer field, it should be in the field itself.
Check the following code as I tried it myself and it worked without issues:
https://library.adaptavist.com/entity/dynamic-select
Let me know if you have any questions.
Best,
Fadoua
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks! I did triy it in the field itself too with the same result. I'll check that web page.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You will have to add a server script for both field 2 and 3 not in field 1
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you! When I create Fields 2 and 3 should I set some defaults for those?
They are still not being updated with the new options from the script, even though it is going through the right sections of the script according to debug messages..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you please share the script for each field exactly the way you have it?
Best,
Fadoua
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here it is. Right now I am just trying it in jusr field 2
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Setting the field options is very straightforward. You only need to pass a list value to it.
However, in your code, you appeared to have passed a Map, hence the issue.
Please modify your code accordingly to something like this:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def list1 = getFieldById(fieldChanged)
def list1Value = list1.value.toString()
def list2 = getFieldByName('List2')
def list3 = getFieldByName('List3')
def list2NewOptions = ['Option1', 'Option2', 'Option3', 'Option4', 'Option5']
def list3NewOptions = ['Choice1', 'Choice2', 'Choice3', 'Choice4', 'Choice5']
if(list1Value == 'Zone1') {
list2NewOptions = ['Option1', 'Option2']
list3NewOptions = ['Choice1, 'Choice2']
} else if(list1Value == 'Zone2') {
list2NewOptions = ['Option3', 'Option4']
list3NewOptions = ['Choice3, 'Choice4']
} else if(list1Value == "Zone3") {
list2NewOptions = ['Option5']
list3NewOptions = ['Choice5']
}
list2.setFieldOptions(list2NewOptions)
list3.setFieldOptions(list3NewOptions)
Please note that the sample working code above is not 100% exact to your environment. Hence you will need to make the required modifications.
Below is a screenshot of the Server-Side Behaviour configuration:-
In the example code above, the Server-Side Behaviour is configured for List1. In your case, you must configure a Server-Side Behaviour for the Leve 1 field.
Also, please note, when configuring a Server-Side Behaviour, the field the Server-Side Behaviour is added for must be declared as:-
def leve1Field = getFieldById(fieldChanged)
The fieldChanged option must be used to ensure that the Behaviour correctly detects when a change has been made to a particular field and triggers the Behaviour accordingly.
I am also including a couple of test screenshots for your reference:-
1. On the create screen, when an option is selected from List1 as shown in the screenshot below, the options in List2 and List3 are also filtered accordingly in the following screenshots
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.
Thanks for replying, Ram. I am still having the same problem. It looks like the code is working as it's supposed to, but the new lists are not being displayed. Here is your script with my modifications:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please clarify what version of Jira and ScriptRunner runner you are currently using.
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.
Great to hear the solution worked. :-)
Please accept the answer.
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.
@Ram Kumar Aravindakshan _Adaptavist_ I am using Jira Software 9.12.1 and ScriptRunner 8.21.0 but I see there is an update for version 8.27.0. I will update to to this latest version.
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.