Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

The option to limit multiple selection fields

arno
Contributor
July 3, 2023

Hi All

We set a multi-choice field in jira. We expect different question types to see different choice values. I know that scriptrunner behaviours can implement this, but the effect is still the same after I set it

My statement Settings are as follows:

def field = getFieldByName('Product test')

field.setFormBalue(['test1','test2'])

field.setFieldOptions(['test1'])

I tried the above two methods, but none of them worked, and the field still showed all the option values

2 answers

1 accepted

2 votes
Answer accepted
Sayed Bares [ServiceRocket]
Community Champion
July 3, 2023

Hi @arno ,

Something like this should work:

def selectField = getFieldByName('Product test')

selectField.setFieldOptions(['test1'])

(i) You should see only test1 option when creating/editing issue

What is your Jira and Scriptrunner version? can you share a screenshot from your behavior? have you set the mapping to the correct project and issue type? is Product test a single select field?

arno
Contributor
July 3, 2023

Hi @Sayed Bares [ServiceRocket] 

Thank you for your reply

I have found the cause of the problem, because I did not store the corresponding code in the field "Product test" configuration

I would like to ask if I can add some conditions to limit the display of the options, for example, when I select "test" in the custom field (Product), the product test option values are test1 and test2

My current configuration is as follows


def field1 = getFieldByName('Product test')
def first = getFieldByName('Product')
def value = first.getValue()
if (value == 'test'){
    field1.setFieldOptions(["test1","test2"])
}

But this is not real time (I don't know if you can understand what I mean), I want the effect to be that after I select the Product, the corresponding option is displayed immediately, rather than I save the corresponding value and then display the relevant option
Sayed Bares [ServiceRocket]
Community Champion
July 3, 2023

@arno I know exactly what you mean and to achieve real time editing, you will just need to add a script for your field which you want to check it in real time in this case it should be Product field and the script should look something like this:

def formField = getFieldById(getFieldChanged())

def ProductTest = getFieldByName('Product test')

def Product = formField.getValue()

if (Product == "test") {

ProductTest.setFieldOptions(['test1','test2'])

}

else

{

ProductTest.setFieldOptions(['test1','test2','test3'])

}

tets.png

Sayed Bares [ServiceRocket]
Community Champion
July 3, 2023
arno
Contributor
July 3, 2023

Hi  @Sayed Bares [ServiceRocket] 

Thank you for your reply

According to your method, I have tried, which is exactly the result I need, thank you for your help

0 votes
Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 3, 2023

The issue is that #setFieldOptions() expects a Map as parameter (id:value kind of a thing), or iterable list of Options whereas ['xx'] in groovy would be a String array (or list, idk).

More importantly though check https://library.adaptavist.com for new scripts, it contains your use case here: https://library.adaptavist.com/entity/basics-behaviours-set-multi-select-options-value

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events