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

convertToSingleSelect behaviour

Bartek Zukowski November 30, 2017

Hi,

We use convertToSingleSelect in two ways:

1. With a static list of values set in the script of the REST endpoint that the converted field is linked to - useful when we need a hideable single select list.

2. With an endpoint that is connected to an external database - to get data that can be updated by users that are not Jira admins but have access to that external database.

In the first scenario this behaviour is working like this:

When you select an option from the list that option is no longer accessible if you want to change selected option. So with every option that you select, the list is becoming shorter and shorter. 

In the second scenario when you select an option you cannot change it at all because the list becomes empty. You need to reload whole form to see full list again.

Is it possible to configure such converted field to behave the same way as a normal single select list? So all values remain in the list no matter how many times a user changes his mind while reporting new ticket. 

Regards,

Bartek

3 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
2 votes
Answer accepted
Jenna Davis
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.
December 5, 2017

Hello, 

For your first scenario, this should be possible. Could you please send me an example of the code you're using currently? I might be able to see where you need to make changes. 

For the second, you might take a look at this example: 

https://scriptrunner.adaptavist.com/latest/jira/behaviours-conversions.html#_walkthrough_choose_from_a_database_table

Or, there are several other select list conversion examples here:

https://scriptrunner.adaptavist.com/latest/jira/behaviours-conversions.html

Jenna

Bartek Zukowski January 11, 2018

Hi Jenna,

In the first scenario we use following behaviour to convert a text field to single select list:

def score = getFieldById("customfield_16403")

score.convertToSingleSelect([
ajaxOptions: [
url : getBaseUrl() + "/rest/scriptrunner/latest/custom/scores",
query: false,
formatResponse: "general",
],
css: "max-width: 500px; width: 500px",
])

And a simple custom endpoint:

import groovy.json.JsonOutput
import groovy.transform.BaseScript
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import javax.servlet.http.HttpServletRequest
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

class pozycja {
def value
def label
}

scores () { MultivaluedMap queryParams, String body,HttpServletRequest request ->

def lista = ['1','2','3','4','5']
def result = []
def map = [:]

lista.each {
result << new pozycja(value:it, label:it)
}

map.put('items', result)

Response.ok(JsonOutput.toJson(map)).build()

As for the second scenario -  I have looked into your examples (without it I couldn't make it running in the first place;) ) but I haven't found anything to make it work exactly as a true single select list.

Regards,

Bartek

Jenna Davis
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.
January 12, 2018

Hello, 

Here's a simple example of a REST endpoint that does something similar to what you're wanting (for your first question) :

import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript

import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

@BaseScript CustomEndpointDelegate delegate

doSomething() { MultivaluedMap queryParams ->

    def query = queryParams.getFirst("query") as String
    def fullList = [:]
    def originalList = ['A', 'B', 'C'] // test list, put your list here!    
def list = [] if(query){ def length = query.length() originalList.each{ if(it.substring(0, length) == query){ list.push(it) } } } else{list = originalList} fullList = [ items: list.collect { [ value: it, html : it, label: it, ] }, ] return Response.ok(new JsonBuilder(fullList).toString()).build() }

 And here's the behaviour that goes with it:

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

My example probably needs some more intensive error handling added, so if something causes it to break keep that in mind. Hopefully that will help you out with your first question!

As far as querying the database, I'm not sure what you mean by making it a true single select. Can you send what you're doing currently?

Jenna

Like Yoav Ashkenazi likes this
Bartek Zukowski January 22, 2018

Wow, that is clever! Thanks a lot, Jenna! I will try to implement this approach also to our second scenario (with a database).

0 votes
SWAPNIL SRIVASTAV October 30, 2019

Hello @Bartek Zukowski  and @Jenna Davis ,

I have tried the above Rest Endpoint and behaviour, but it is not working for me.

Could you please help.

Thanks and Regards,

Swapnil Srivastav.

0 votes
SWAPNIL SRIVASTAV October 30, 2019

Hello @Bartek Zukowski  and @Jenna Davis ,

I want to create a customized select list where the options are:

<value of a custom field in the particular issue><space><summary of the same issue>

and the no of options should  be same as the no of issues in a particular project which should be updated dynamically whenever a new issue is created.

Could you please help me.

Thanks and Regards,

Swapnil Srivastav

TAGS
AUG Leaders

Atlassian Community Events