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
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:
Or, there are several other select list conversion examples here:
https://scriptrunner.adaptavist.com/latest/jira/behaviours-conversions.html
Jenna
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Wow, that is clever! Thanks a lot, Jenna! I will try to implement this approach also to our second scenario (with a database).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.