JQL sorted by "field", how to determine if a field is sortable

Hi I am trying to use JQL to sort issues by fields. List of issues can be sorted by a field provided by user.
However, as it turns out, not all fields can be used as parameter to JQL order by clause

e.g.:

/rest/api/2/search?jql=assignee+%3D+currentUser()++ORDER+BY+cf%5B12400%5D+ASC

This will fail e.g. for “Organization” custom field with message:

["Field 'cf[12400]' does not support sorting."]

I am trying to narrow list of fields that can be sorted by. I have looked into /rest/api/2/field, it returns meta for each field, and there is a properties called orderable, e.g:

{ clauseNames: Array(2),
  custom :true,
  id: "customfield_12400",
  key:"customfield_12400",
  name:"Organizations",
  navigable:true,
  orderable:true,
  schema: {
        custom:"com.atlassian.servicedesk:sd-customer-organizations",
        customId:12400,
        items:"sd-customerorganization",
        type:"array",
    }
    searchable:true
}

However for “Organization” field, property orderable is set to “true”, so I assume the role of the property is different.

So far i have found 2 fields not supporting sorting: “Organization” and “Approvers”.

For field “Approvers” it gets strange, because its type=array and array items=user, exactly the same as e.g. for “Request participants” field which can be sorted

Is it possible to determine which field can be sorted using JQL using current API?

1 Like

Hi @maciej.dudziak,

Generally, ordering is not supported where a piece of content can have multiple values for a field, for instance ordering is not supported on labels. Refer to JQL Advance Searching - ORDER BY for more information.

Thanks!

Cheers,
Anne Calantog

1 Like

Hi @acalantog,

That does not seem to be true anymore. When you use queues for JIRA SD you can actually sort by Labels

/rest/servicedesk/1/servicedesk/CSD/issuelist?jql=project+%3D+CSD+ORDER+BY+labels+ASC&columnNames=issuekey&columnNames=summary&columnNames=created&columnNames=updated&columnNames=duedate&columnNames=labels

status 200

Hi @maciej.dudziak,

Oops. I posted the wrong link (that’s for CQL). For JQL’s ORDER BY refer to this. One way to also look at the available fields for sorting is, when you’ve searched in jira with order by clause, there’d be a dropdown below the jql search field with the order by options. I’ve checked Advance Searching - Fields Reference and most of the fields are sortable.

Also, if you’re interested, vote for Field Organization is not sortable in a JQL.

Thanks!

Cheers,
Anne Calantog

I am aware of the dropdown :slight_smile: However I need some programatic way to determine orderable fields. Especially, when it comes to custom fields which I cannot simply put on a blacklist.

Maybe rest/orderbycomponent/latest/orderByOptions could be made public, or some property could be added to rest/api/2/field?

I have just found that fields with no clauseName returned by /rest/api/2/field are not orderable. (clauseNames property is an array, but sometimes it is empty)
clauseName need to be used in JQL after ORDER BY clause

2 Likes

Beside those without clauseName, there are some, mostly coming from Service Desk which I can filter out by type:
Customer Request Type (type: sd-customerrequesttype)
Satisfaction ( type: sd-feedback)
Organizations (type: sd-customerorganization)
Approvals (type: sd-approvals)