Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Order ScriprRunnner Calculated Field

Pedro Felgueiras
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.
March 28, 2022

I have a calculated field that divides two numbers. The division works correctly and I'm able to format the number with the decimal places that I need.  

 

The problem is when I try to order the field. It seams that it's ordering as a text and not a number. the out put that i got is 1.0 2.0 2.6 20.0 4.0 ... 

 

The searcher is "Number Searcher" and the output is cast to Double. 

 

Any tips on how to order this as numbers ? 

2 answers

1 vote
Antoine Berry
Community Champion
March 28, 2022

Hi @Pedro Felgueiras ,

I just tried it with a test number calculated field and the ordering was correct when using a filter.

Could you please share your script and a screenshot of your configuration / filter ?

Pedro Felgueiras
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.
March 28, 2022

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def f1 = customFieldManager.getCustomFieldObject("customfield_XXXXX")
def f2 = customFieldManager.getCustomFieldObject("customfield_XXXXX")


def f1v = (issue.getCustomFieldValue(f1) ?: 0) as Double
def f2v = (issue.getCustomFieldValue(f2) ?: 0) as Double


Number val = f1v / f2v

return val

Like Antoine Berry likes this
Antoine Berry
Community Champion
March 28, 2022

I stand corrected,

I have used a similar script and got the same issue. I tried multiple scripts and return types, re-indexing the project, field searchers... Without success.

Also I have searched in ScriptRunner's documentation without any luck. So I hope someone from Adaptavist can answer this.

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.
March 28, 2022

What template did you use in the scripted field settings?  (Not the search, that looks right, but the template in the scripted field settings themselves)

Pedro Felgueiras
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.
April 1, 2022

We are using "Number Field" as the template

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.
April 13, 2022

Ok, well, I can replicate that behaviour:

  • Create custom field
  • Go to SR and put the script in, changing the template to numeric
  • Create a load of issues that exhibit the failure to sort
  • Remember that I have not changed the searcher, and go do that, selecting "number range"

Still got the text-like sort

To fix it: re-index after changing the searcher!

 

(I forgot - we did have a bug in SR 5.something that broke number searches for a while, but I tested with Jira 8.20 and SR 6.48, and it all worked.  I think we should check versions)

Suggest an answer

Log in or Sign up to answer