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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

ScriptRunner IssuePicker Ignoring ORDER BY

Edited

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

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

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?

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