It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Samuele Gantner Oct 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?


3 answers

1 accepted

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

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

Samuele Gantner Oct 16, 2012

Thanks Jamie, here is the bug

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 Oct 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
slothstronaut Jun 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?






Joshua Yamdogo [Adaptavist] Community Leader Jul 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 Jul 18, 2017

Thank you! I must have overlooked the Searcher Option.

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


0 votes
Karla Russell Oct 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

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Next-gen

Introducing subtasks for breaking down work in next-gen projects

Teams break work down in order to help simplify complex tasks. This is often done iteratively, with tasks being broken down into smaller tasks and so on until the work is accurately captured in well-...

1,055 views 13 15
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you