Sort on Script Field only works in lexicographic order (not in numerical order)

Samuele Gantner October 16, 2012

I have a Script Field called Value returning an integer representing the business value of a feature (the field is calculated based on other fields using Groovy). Its template is Number Field, the return type is int.

Unfortunately when using this field for sorting issues the order is lexicographic. What I need is to have proper integer comparisons and ordering.

Any idea about the possible cause?

Thanks,
Sam

3 answers

1 accepted

0 votes
Answer accepted
JamieA
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 16, 2012

The template just governs how it's displayed, not the sort. I'm afraid I have hard-coded it to compare as Strings.

To deal with this I need to give the user the option to "overload" that, but then you're moving away from a "simple scripted field" that is supposed to be easy to use for non-programmers into a nightmare of a UI with options for everything.

I may implement it like this: "if the user has provided an 'int compare'" method in their script, use that, otherwise use the default".

You could also try configuring it with the number searcher, but I don't think that's going to make any difference.

JamieA
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 16, 2012

A bug report containing just a summary and a link to this would be helpful.

Samuele Gantner October 16, 2012

Thanks Jamie, here is the bug https://studio.plugins.atlassian.com/browse/GRV-178

Having this interpreted as an int would really be great. One of the other features I would like is to be able to filter my rapidboard based on that value, but of course I can only do it if it is correctly interpreted.

As a workaround for sorting:

if (val("Customer priority") == "[Yes]") result = 100;
else result = 5 *(getValue("Demo value") + ...);

return result.toString().padLeft(3, '0')

JamieA
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 16, 2012

> One of the other features I would like is to be able to filter my rapidboard based on that value

That *will* work if you utilise the number searcher. But then of course you won't be able to use workaround for sorting that you have.

0 votes
Karla Russell October 16, 2017

I am still facing this problem.

In both custom field edit and scripted field screens we've selected Number field and re-indexed several times.  No joy.

I'm attaching screenshots.  Thanks for the help!

 

Screen Shot 2017-10-16 at 2.23.13 PM.pngScreen Shot 2017-10-16 at 2.17.31 PM.pngScreen Shot 2017-10-16 at 2.17.07 PM.png

0 votes
slothstronaut June 28, 2017

Is this still a thing in 2017?

I have a number field template scripted Field in ScriptRunner 5.0.4. / JIRA 7.x for 'days since last update', and can't get it to sort properly :( 

It would make solely numeric fields more or less useless if they cant be sorted properly or jql'ed by range?! For e.g. 71 is between 761 and 758.

Sadly I couldn't find any workaround for this. Am I missing some configuration or some other thing here? Or is this simply not possible at the moment because of hardcoded lexicographic sort?

Greets!

 

 

 

 

Joshua Yamdogo @ 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.
July 18, 2017

Hey slothstronaut,

I am not sure if you ever figured this out, but I just ran into this exact issue. I was having trouble getting my scripted fields to search by their numeric value. All you need to do is:

  • Go to the Custom Fields page
  • Find the scripted field 
  • Click edit
  • Change the Search Template to Number Searcher
  • Reindex

This should allow JIRA to sort the numbers based on their numeric values. It worked for me. See attached image. 

 
 That will allow your fields to be sorted numerically.
slothstronaut July 18, 2017

Thank you! I must have overlooked the Searcher Option.

By first looks, I think this solved my Issue!!

 

Suggest an answer

Log in or Sign up to answer