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

Sorting and searching of scripted number field does not work

Tobias Lubinski September 10, 2020

Hi there,

 

I have a scripted number field which gives me the number of requirement tests for a story. The script only executes a JQL (type = Testfall AND issue in requirementTests(" + issue.key + ")) and returns the search count as double value. This works fine.

When I try to use this field in issue search I get the results displayed but can not use it in search or while sorting issue by this field value.

Here the script:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.DefaultSearchService
import com.atlassian.query.Query
import com.atlassian.jira.user.ApplicationUser

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(DefaultSearchService)
def ApplicationUser user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

if (user != null && user.isActive()) {
// edit this query to suit
Query query = jqlQueryParser.parseQuery("type = Testfall AND issue in requirementTests(" + issue.key + ")")
if (searchService.searchCount(user, query).doubleValue()) {
return searchService.searchCount(user, query).doubleValue()
} else {
return 0
}
}

 

Is there anyone who can help me?

 

Best Regards

Lubi

 

3 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Thomas Litherland
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 30, 2024

Hi all,

I'm very late to this particular post but thought I'd add some information for those who still may come across the same issue that I have recently, while finding most older posts like this never had a full answer.

After various attempts at troubleshooting and finally getting to the bottom of it, I will list all things to check/do:

  • Ensure the Template is set to Number Field in the scripted field config (the default is a text field)
  • Likely overkill considering the template defines which data type the script is expecting - ensure to be confident that you script returns a numerical data type such as Long, Double or Integer.
  • This is the important one I have never seen in answers to these postsin Scriptrunner's Fields section/tab, when searching for your affected field, before you click on Edit, or any other option, you will see a Searcher type for the field. In some cases this will be be None or Free Text Searcher. This needs to be set to Number Searcher to ensure the JQL search will interpret the values loaded for this field can be sorted correctly. This was the final thing I had not corrected that once updated fixed my issue.
  • Finally, if this only relates to one project, re-index the project the scripted field is used by. If it is used instance-wide, re-index your instance to ensure the config is properly updated for JQL queries.
0 votes
Tobias Lubinski November 12, 2020

I have updated Scriptrunner to Version 6.13.1 but sorting and searching does still not work. What can I do else?

Nic Brough -Adaptavist-
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.
November 12, 2020

I'd raise this directly with the SR support team.

The numeric scripted field I've got that returns like yours does works fine when the number-range searcher is selected for it.  Although I have a nagging doubt it returns a long rather than a double, I can't imagine that would be the answer.

0 votes
Nic Brough -Adaptavist-
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.
September 17, 2020

In the script settings, is the output template set to be a number field?

When you go to Custom fields -> Your scripted field -> Edit, what do you have set for a "searcher" for it?

Tobias Lubinski October 1, 2020

Hi Nic,

i already tried number search for exact number and number range.

Regards

Lubi

Nic Brough -Adaptavist-
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.
October 3, 2020

Did you re-index after changing the searcher?

Tobias Lubinski October 4, 2020

Yes

TAGS
AUG Leaders

Atlassian Community Events