ScriptRunner IssuePicker Ignoring ORDER BY

Dave Hunt February 1, 2022

We have a custom scripted field configured as a IssuePicker field, which uses a JQL query to populate a list of options in a Select field.

The issues are filtered correctly according to the JQL, however the ORDER BY in the JQL is being ignored. We're trying to order the results alphabetically by Summary in the select options, however the order appears to be random each time.

When I test the JQL in Jira search, the results are ordered correctly, but it doesn't maintain that when being used in the IssuePicker.

Is there another way to determine the order in which issue results appear in the IssuePicker field?

2 answers

1 accepted

1 vote
Answer accepted
Dave Hunt May 26, 2023

For those with the same problem - there doesn't seem to be a built-in solution for sorting for the IssuePicker field.

I got around it by using the CustomPicker field and adding the query to the search method:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.scriptrunner.canned.jira.fields.model.PickerOption
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.Issue

def searchService = ComponentAccessor.getComponent(SearchService)
def queryParser = ComponentAccessor.getComponent(JqlQueryParser)
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

search = {
String inputValue ->
def queryString = "project = MT AND issuetype in subTaskIssueTypes()"
if (inputValue != "") {
queryString += " AND Summary ~ \"*${inputValue}*\""
}
queryString += " ORDER BY summary ASC"
def query = queryParser.parseQuery(queryString)
def searchQuery = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
return searchQuery.results
}

getItemFromId = { String id ->
return ComponentAccessor.getIssueManager().getIssueObject(id)
}

toOption = { Issue issue, Closure highlight ->
new PickerOption(
value: issue.key,
label: issue.summary,
html: "${highlight(issue.summary, false)}",
icon: issue.getIssueTypeObject().getIconUrl()
)
}

This respects the ORDER BY in the query

Alfira Merinova May 26, 2023

Hi Dave,

Thanks a lot for this example. I tried your code with reverse order 

" ORDER BY summary DESC"

And also tried without any order.

In all cases in the search results it orders records in ASC.

Could you please check this?

0 votes
Dave Hunt May 23, 2022

I've been unable to find any information at all about how the Issue Picker actually handles sorting, it seems pretty random.

Does anyone have any ideas or information that might lead me in the the right place? Thank you

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events