Cannot accurately sort by scripted field

Alex Christensen Community Champion Sep 17, 2015

I've created a scripted field called Work Effort Progress, but I'm not able to sort (ASC or DESC) on this field in the Issue Navigator unless I include "Work Effort Progress" is not EMPTY in the JQL. I don't think that I should need to do this because none of the fields have an empty value (i.e. "Work Effort Progress" is EMPTY doesn't return any issues at all). I've re-indexed multiple times and the issue is still occurring.

Here is the script I'm using.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Category
import com.atlassian.jira.config.SubTaskManager
SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager();
Collection subTasks = issue.getSubTaskObjects()
Double timeSpentTotal = 0
Double remainingEstimate = 0
Double progress = 0

if (subTaskManager.subTasksEnabled && !subTasks.empty) {
    subTasks.each {
        if (it.getTimeSpent() != null) {
            timeSpentTotal += it.getTimeSpent()
        if (it.getEstimate() != null) {
            remainingEstimate += it.getEstimate()
else if (!subTaskManager.subTasksEnabled || subTasks.empty) {
    if (issue.getTimeSpent() != null) {
        timeSpentTotal = issue.getTimeSpent()
    if (issue.getEstimate() != null) {
        remainingEstimate = issue.getEstimate()
if (timeSpentTotal > 0) {
	progress = ( timeSpentTotal / ( timeSpentTotal + remainingEstimate ) ) * 100
return progress.round(2)

And here is my custom template (I added a pseudo progress bar far a visual representation of progress):

#if($value > 0.01 && $value <= 10)
    <div><strong>[<span style="color:green;font-weight:bolder">></span></strong>>>>>>>>>><strong>]</strong> $value%</div>
#elseif($value > 10 && $value <= 20)
    <div><strong>[<span style="color:green;font-weight:bolder">>></span></strong>>>>>>>>><strong>]</strong> $value%</div>
#elseif($value > 20 && $value <= 30)
    <div><strong>[<span style="color:green;font-weight:bolder">>>></span></strong>>>>>>>><strong>]</strong> $value%</div>
#elseif($value > 30 && $value <= 40)
    <div><strong>[<span style="color:green;font-weight:bolder">>>>></span></strong>>>>>>><strong>]</strong> $value%</div>
#elseif($value > 40 && $value <= 50)
    <div><strong>[<span style="color:green;font-weight:bolder">>>>>></span></strong>>>>>><strong>]</strong> $value%</div>
#elseif($value > 50 && $value <= 60)
    <div><strong>[<span style="color:green;font-weight:bolder">>>>>></span></strong>>>>>><strong>]</strong> $value%</div>
#elseif($value > 60 && $value <= 70)
    <div><strong>[<span style="color:green;font-weight:bolder">>>>>>></span></strong>>>>><strong>]</strong> $value%</div>
#elseif($value > 70 && $value <= 80)
    <div><strong>[<span style="color:green;font-weight:bolder">>>>>>>></span></strong>>>><strong>]</strong> $value%</div>
#elseif($value > 80 && $value <= 90)
    <div><strong>[<span style="color:green;font-weight:bolder">>>>>>>>></span></strong>>><strong>]</strong> $value%</div>
#elseif($value > 90 && $value < 100)
    <div><strong>[<span style="color:green;font-weight:bolder">>>>>>>>>></span></strong>><strong>]</strong> $value%</div>
#elseif($value == 100)
    <div><strong>[<span style="color:green;font-weight:bolder">>>>>>>>>>></span></strong><strong>]</strong> $value%</div>
    <div><strong>[</strong>>>>>>>>>>><strong>]</strong> 0.0%</div>

I can search on this field just fine and everything else about this field works wonderfully except for the sorting capabilities. When I try to sort, I get this error message:

"Error occurred communicating with the server. Please reload the page and try again."

If I add in the JQL mentioned above, I can sort just fine. Any ideas on what might be causing the error or where I can look to try to diagnose the issue? Thanks for your help!

3 answers

This widget could not be displayed.

Which indexer/searcher is the custom field configured with?

This widget could not be displayed.
Alex Christensen Community Champion Sep 18, 2015

Hi, Jamie - this scripted field is using a Number range searcher.

This widget could not be displayed.

I used the following field code:

def modulus =
modulus == 0 ? null : modulus as Double

and the sorting worked ok, except it sorted them in the order null, 3, 2, 1. Which is not intuitive to me.

If you're getting an error there should be a stack trace... although it might be truncated. Can you find it and post it?

Alex Christensen Community Champion Sep 21, 2015

Hi, Jamie - without making any changes to my field or anything today, I see that my field is sorting correctly. Not sure why it's working now and wasn't before. After creating the field, I re-indexed and checked, but it didn't work then. It is now! Appreciate your input and quick responses - thanks!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Friday in Jira

New 5k User Limit and Other Cloud Updates

Hi all! Lauren here from the Enterprise Cloud marketing team.  I have some exciting Cloud updates from #AtlassianSummit that I wanted to share. We want everyone in your organization to be ab...

119 views 0 3
Read article

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