How can I add custom fields available for "Sort By" in the Planning Board?

Eric Salonen
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 21, 2012

Hi guys,

We wish to sort cards in the planning board according to our own custom field, which we have developed. In order to do this, the user must first modify the context in the planning board and go to the "Sorting" tab (as show in pic 1). The problem is that the sorting tab only shows certain custom fields in the list, as I can not see our own custom field called "Sort Key" in this list.

The custom field we created is a very simple custom field and its purpose is to sort issues in order (in the issue navigator) with parents and subtasks underneath each other, regadless of when a subtask was created.

For example, if a user sorts the issue navigator by issue key, some of the subtasks would display later in the results, because the subtask was created much later (and thus receiving a bigger issue key). However, when issues are sorted according to our sort key, subtasks appear under the respective parent level issue (vice versa when order is DESC) regardless of when the actual subtask was created. The Sort key is a combination of the parent level issues key and a number value of the subtask's key.

Example: We have parent level issue FB42-12 which has a subtask FB42-21. FB42 is the key for our project. Sort key for the parent level issue is FB42-12 and for the subtask FB42-12-21.

The source code for this custom field is as follows:

package com.customer.jira.remark.plugin.customfield;

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.customfields.impl.CalculatedCFType;
import com.atlassian.jira.issue.customfields.impl.FieldValidationException;
import com.atlassian.jira.issue.fields.CustomField;

public class SortField extends CalculatedCFType {

    public String getStringFromSingularObject(Object arg0) {
        return null;
    }

    public Object getSingularObjectFromString(String arg0)
            throws FieldValidationException {
        return null;
    }

    public Object getValueFromIssue(CustomField cf, Issue issue) {
        String issueKey = issue.getKey();
        
        if (issue.isSubTask()) {
            String projectKey = issue.getProject().getString("key").toString();
            String parentKey = issue.getParent().getString("key").toString();
            
            return parentKey + issueKey.substring(projectKey.length());
            
        } else {
            return issueKey;
        }
    }

}

The question is, why does not the Custom Field show in the list in "Sort by" when editing the context?

Cheers,
Eric Salonen
Ambientia Ltd

 

5 answers

1 accepted

0 votes
Answer accepted
Eric Salonen
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.
September 11, 2015

Obsolete

0 votes
MattS
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.
September 30, 2014
0 votes
Błażej O_
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.
December 16, 2012

Hello there.

Have you tried re-indexing?

I think sorting might be also connected to search index. Try setting a search template to the custom field (edit custom field in the administration section) and re-index again.

0 votes
Eric Salonen
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.
August 27, 2012

Hi guys,


I would really love to get an answer for this question as it is baffling me quite a bit? Any help from the internets people?

Cheers,
Eric Salonen

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 21, 2012

You need to implement it as a sortable field.

i.e.

public class SortField extends CalculatedCFType implements SortableCustomField {

...

public int compare(final Double customFieldObjectValue1, final Double customFieldObjectValue2, final FieldConfig fieldConfig) {

return customFieldObjectValue1.compareTo(customFieldObjectValue2);

}

The compare logic you do basically needs to return -1, 0 or 1, meaning a<b, a==b and a>b (I've cheated there - my data is numerics, so the compare function is a doddle)
Eric Salonen
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 15, 2012

Hi Nic,

Thanks for you reply mate. I completed the following function for implementing the SortableCustomField:

public int compare(final String customFieldObjectValue1, final String customFieldObjectValue2, final FieldConfig fieldConfig) {
return customFieldObjectValue1.compareTo(customFieldObjectValue2);
}

Is this correct? The field is still not visible in the Sort By view in GreenHopper.

Any help still left?

Eric Salonen
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.
May 1, 2012

Hi everybody,


Is there anybody that con confirm my question above?

Cheers,
Eric

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 1, 2012

Does it implement "sortable field" as well? That's worked for my code, I don't know if there's something else I've missed.

Eric Salonen
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.
May 1, 2012

Hi Nic,


Thanks for the reply, yes it does implement the Sortable field as well, same way as in your example. Hmmm, I wonder what it might be....

Suggest an answer

Log in or Sign up to answer