Scriptrunner Behaviour
Asked by Volodymyr:

Good afternoon,  
I was given a request asking for the customfield (select list (single choice)) to become (multiple choices) for two issue types, and for all others to remain single choice. Could someone tell me if this can be done using Scriptrunner Behaviours and how?  
I've seen methods like convertToMultiSelect and others, but have a problem with understanding how they work and how to make a multi-select choices from single choice.

![screenshot_1.png](/t5/image/serverpage/image-id/331051iE9EBDB3BC7A724C4/image-size/large?v=v2&px=999 "screenshot_1.png")![screenshot_2.png](/t5/image/serverpage/image-id/331049i41DA564E281B81DA/image-size/large?v=v2&px=999 "screenshot_2.png")![screenshot_3.png](/t5/image/serverpage/image-id/331050i24464D30F365985E/image-size/large?v=v2&px=999 "screenshot_3.png")

At the moment the view screen shows one value (screenshot_1), when editing the field becomes multiple choices (screenshot_2), but when saving all values, only the last value remains in the field (screenshot_3).


Answers:
author: Ram Kumar Aravindakshan _Adaptavist_
body: Hi [@Volodymyr](/t5/user/viewprofilepage/user-id/4357698)

To answer your question, yes, you can do this by converting a Single-Line Text Field to either a Single-Select List or a Multi-Select List. You will need to use ScriptRunner's Behaviour and the Select List Conversion, i.e. use either the convertToSingleSelect or convertToMultiSelect option depending on your requirement.

Please refer to this [ScriptRunner Documentation](https://docs.adaptavist.com/sr4js/latest/features/behaviours/behaviours-examples/select-list-conversions) for more information and examples.

In regards to converting it to either single or multi-select based on the issue type, you will need to use the Behaviour Initialiser and use the issueContext to control the conversion, i.e. something like:-  

```
if (issueContext.issueType.name == 'Bug') {
    getFieldByName("TextFieldB").convertToMultiSelect([ // <1>
        ajaxOptions: [
                url           : getBaseUrl() + "/rest/scriptrunner/latest/custom/githubRepoQuery", // <2>
                query         : true, // keep going back to the sever for each keystroke
                minQueryLength: 4, // <3>
                keyInputPeriod: 500, // <4>
                formatResponse: "general", // <5>
        ]
    ])
} else if (issueContext.issueType.name == 'Story') {
    getFieldByName("TextFieldB").convertToSingleSelect([ // <1>
        ajaxOptions: [
                url           : getBaseUrl() + "/rest/scriptrunner/latest/custom/githubRepoQuery", // <2>
                query         : true, // keep going back to the sever for each keystroke
                minQueryLength: 4, // <3>
                keyInputPeriod: 500, // <4>
                formatResponse: "general", // <5>
        ]
    ])    
}
```

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

comments: author: Volodymyr
body: I read the documentation and my question still remains - How to convert select list-single choice to select list-multiple choices.


author: Ram Kumar Aravindakshan _Adaptavist_
body: Hi Volodymyr,

Based on what condition do you want to do the conversion?

If it's based on the issue type, I have already answered it in my previous comment.

Thank you and Kind regards,  
Ram


author: Volodymyr
body: Hi [@Ram Kumar Aravindakshan _Adaptavist_](/t5/user/viewprofilepage/user-id/2988015) ,  

I see a method for converting the field and the conditions under which the code is executed, but I can't save more than one value and values are only displayed in the Edit Screen.  
I can't understand how the code should work and what should be written in the end.  
![1.png](https://community.atlassian.com/t5/image/serverpage/image-id/331288i5F042FEA044686D1/image-size/large?v=v2&px=999 "1.png")![2.png](https://community.atlassian.com/t5/image/serverpage/image-id/331287iA6AB8C029D42106B/image-size/large?v=v2&px=999 "2.png")  

The field allows me (due to the method "convert") to select more that one value, but only keeps the last one when saving, so I can't figure out what I need to do to avoid it.  

*I've tried your code, but it doesn't change anything, so I don't know exactly where to change it.*   

Thank you


Tags: behaviours

data-center

jira-data-center

scriptrunner