minQueryLength and keyInputPeriod being ignored for Select List Conversion Edited


Hello All,

I am using a select list conversion with the following initializer function in my behavior:

    ajaxOptions: [
        url: getBaseUrl() + "/rest/scriptrunner/latest/custom/myFunction",
        query: true,
        minQueryLength: 4, 
        keyInputPeriod: 500,
        formatResponse: "general"

 The problem is whenever I click on the custom field in the view/edit screen, it immediately starts querying, ignoring the minQueryLength parameter of 4 and the keyInputPeriod parameter as well.

I also noticed that as I type into the field, it thinks for a while, clears out the text from the form, and returns an empty list.  Looking at the network traffic, I see that every time I make a key input, it fires off another request to the AJAX url, eventually cancelling the previous requests, but every time it cancels, it also clears the form and the results.  This creates a really clunky and almost unusable user experience.

1 answer

0 vote

I can't seem to reproduce this issue you have in the latest version of ScriptRunner. It seems to respect the min query length.

Have you tried the example here? What do you get with that?

Do you have the code for your custom endpoint?

What version of JIRA and ScriptRunner are you using?

I upgraded to ScriptRunner 5.0.1 and am running JIRA Software 7.2.6.

Here is the code for the custom REST endpoint.  The endpoint fetches a list of assignment groups from ServiceNow and the idea is the user will select one of those groups from a drop-down in a JIRA issue (hence the select list conversion).

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

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

import groovy.json.JsonBuilder
import groovyx.net.http.HTTPBuilder
import org.apache.http.HttpRequest
import org.apache.http.HttpRequestInterceptor
import org.apache.http.protocol.HttpContext

import static groovyx.net.http.ContentType.JSON
import static groovyx.net.http.Method.GET

@BaseScript CustomEndpointDelegate delegate


def username = "USERNAME"
def password = "PASSWORD"
def snBaseUrl = "SN_BASE_URL"


def getResponse = { output ->
    return Response.ok(
        new JsonBuilder(output).toString()

def getError = { message ->
    return Response.ok(new JsonBuilder([
        items: [
            value: "None",
            html: "None",
            label: "None"
        footer: message

servicenowassignmentgroups(httpMethod: "GET") { MultivaluedMap queryParams, String body -> 
    def query = queryParams.getFirst("query") as String
    if(!query) {
        query = ""
    def http = new HTTPBuilder(snBaseUrl)
    http.client.addRequestInterceptor(new HttpRequestInterceptor() {
        void process(HttpRequest httpRequest, HttpContext httpContext) {
            httpRequest.addHeader("Authorization", "Basic " + "$username:$password".bytes.encodeBase64().toString())
    def response = http.request(GET, JSON) { req ->
        uri.path = "/api/now/table/sys_user_group"
        uri.query = [ sysparm_query: "nameLIKE$query" ]
        headers.Accept = "application/json"

        response.success = { resp, json -> 
            return json

        response.failure = { resp ->
            return null
    if(response == null) {
        return getError("Unable to retrieve ServiceNow assignment groups")
 def output = response.result.collect { group ->
        def html = group.name
        if (query) {
            html = html.replaceAll(/(?i)$query/) { 
            value: group.sys_id,
            html: html,
            label: group.name
    return getResponse(
            items: output,
            total: output.size(),
            footer: "Choose Assignment Group..."

I tried the example to create a github repo query from the select list conversions page.

The options for minQueryLength and keyInputPeriod do indeed work.

Okay, I don't know why, but I think I figured it out.

In my custom rest endpoint, I moved the getResponse and getError functions INSIDE the servicenowassignmentgroups function, and it works!

Why is that?

I've noticed sometimes there is odd behavior when you have code sitting outside the actual REST endpoint function.  For example, I had a similar endpoint where I defined the "output" variable outside of REST endpoint function, and every call to the endpoint would take the output from the previous run of the endpoint and concatenate the new result.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published 2 hours ago in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

17 views 0 1
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you