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

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

This widget could not be displayed.

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.

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

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')

> 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.

This widget could not be displayed.

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!

 

 

 

 

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.

Thank you! I must have overlooked the Searcher Option.

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

 

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

139 views 2 0
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you