Forums

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

Set a default value on a text field that has been converted into select list (behaviour)

Tomas Azevedo
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 22, 2019

Hi,


I've successfully converted a text field into a select list using behaviours and the convertToSingleSelect method and an REST Endpoint. This was done in the initialiser section of the behaviour.

But now I want to set a value into this field when another field is set. I was able to do this using another behaviour in another text field, but when I try to set the value to the field that is converted into a select list, it simply does not set the value.

I've searched the community and found this post regarding this issue: https://community.atlassian.com/t5/Jira-Core-questions/How-to-set-default-value-in-searchable-list-using-scriptrunner/qaq-p/452603?tempId=eyJvaWRjX2NvbnNlbnRfbGFuZ3VhZ2VfdmVyc2lvbiI6IjEuMCIsIm9pZGNfY29uc2VudF9ncmFudGVkX2F0IjoxNTY5MTY1MTg1MjU4fQ%3D%3D

Has anyone found a solution to this issue? If it is still not possible to set a value into a converted select list, then is it possible to disable the select list in the field and just set the value and mark the field read only if a condition is met?


Thank you.

Best regards,

Tomas Azevedo

1 answer

0 votes
PD Sheehan
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.
September 23, 2019

convertSingleSelect and setFormValue don't seem to be able to work on the same field.

The only workaround I've found is to, instead of using ajaxOptions, you can either call your rest enpoint from the behavior script or gather the option values directly from groovy then add them to the converted field. In this case, the setFormValue will persist.

def map = [:]
map['Test 1'] = "worked"
map['Test 2'] = "worked2"
map['Test 3'] = "worked3"
map['Test 4'] = "worked4"
def testField = getFieldByName("Test")
testField.setFormValue(map.get('Test 1'))
testField.convertToSingleSelect().setFieldOptions(map)

But when using this, you will lose the ability to filter your request in place using the ajaxOptions.query: true

Petr Náhlovský
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 16, 2023

Hi

The above helped me complete the overall solution.

I don't know if it's still up to date :-D.
This line can be added and it works:

 

testField.setFormValue(["Test 1","Test 2"])
Enjoy.
P.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events