Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Set value on text field converted to select list with scriptrunner behaviour

David Arteaga July 27, 2016

I already successfully converted a text field into a single select field using the convertToSingleSelectList method in a behaviour, using a custom rest endpoint. The field works fine and the values get stored. 

I want to know how can I set the value on that field once it has been converted into a select list. 

So far I have tried setting the value of the field to the "value" that gets returned from the rest endpoint for a particular option (using field.setFormValue(...) ), but once the field is converted, no value gets put in the field.

I also noticed that, if I put the "value" in the field, and then convert it into a select list (this second part only works if I do it in another script, not the same one), the option that corresponds to that value gets correctly selected, but the field displays the "value", not the "label" that corresponds to that value. In my case an ID is shown instead of the actual option name, which is displayed if I manually select an option.

 

Any ideas on how to set the value on the field? 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
adammarkham
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 27, 2016

You can set a default for the single select by using the following script:

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

def field = getFieldByName("TextFieldA")

// default value in this map
field.setFieldOptions(["1": "mattbierner/Super-Template-Tetris"])

field.convertToSingleSelect([

    ajaxOptions: [
        url           : getBaseUrl() + "/rest/scriptrunner/latest/custom/githubRepoQuery",
        query         : true, // keep going back to the sever for each keystroke
        minQueryLength: 4,
        keyInputPeriod: 500,
        formatResponse: "general",
    ]

It should be one of the "value" fields you use for the default, you can ignore label and html. This uses the Github example from the documentation: https://scriptrunner.adaptavist.com/latest/jira/behaviours-conversions.html#_create_and_test_endpoint

TAGS
AUG Leaders

Atlassian Community Events