Custom jqlfunction with order by

Pablo
Contributor
February 2, 2021

Hi

I'm trying to create a custom (Scriptrunner used) jqlfunction in groovy and I need this query to return issues in a precise order.

 

Is there any way to create it in scriptrunner? It can be new ORDER BY method or whole JQL Function

 

The issue is that when I create custom JQL FUNCTION which returns query like "id in (xxx, yyy, zzz)" then the result is not displayed exactly the way I've returned it in jqlFunction ;/

 

 

PS I'm not interested in creating customfields just to achieve this

1 answer

1 accepted

0 votes
Answer accepted
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.
February 2, 2021

Jira already has an order by function, so I think I need to start by asking why that is not working for you?

Pablo
Contributor
February 2, 2021

Hi

 

ok :) the big picture is that i need to have a issue filter ordered by components/fixversion/affectsVersion etc size.

 

currently it is quite easy to get by customfields but i need to achieve it by other funcrion/order method

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.
February 2, 2021

Ok, but why?  Order by works for components, fix version, affects version and the other system fields.  Why do you think you need a new function for this?

I guess you could say I'm asking "what exactly are you trying to order by"?  Maybe an example of a sort you cannot do with "order by"?

Pablo
Contributor
February 2, 2021

Hi

as i wrote before

i'm trying to order issues by COMPONTS SIZE or Affected/FixVersion SIZE

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.
February 3, 2021

What do you mean by component size and affectd/fixversion size?

Pablo
Contributor
February 3, 2021

by size i mean number of objects in field

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.
February 3, 2021

Ah, ok, that makes sense.

Yes, you could use Scriptrunner to create a JQL function for this sort of thing.  They are a bit more complicated for this purpose than a scripted field (a scripted field script could be as short as "return issue.getComponents().size()" ), but should be possible.  Get started at https://scriptrunner.adaptavist.com/latest/jira/custom-jql-functions.html

Pablo
Contributor
February 3, 2021

hey

ok lets explain it again :)

The case is i already have my JQLFunction and it gathers issues quite good but the case is that i need to order them in a specific way in issue navigator -> and ONLY THIS PART IS NOT WORKING as expected;/
actual case is that 'm trying to create, WITHOUT CREATING CUSTOMFIELDS, a jql query to order issues by components size desc

I guess I've already checked everything and my jqlFunction is ordering everything correctly but when i open it in jira my results are not ordered the way i'm putting them in script but by jira.id (i guess)

and my question is:
is it possible to have some custom "orderby function" without creating customfield for that?

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.
February 3, 2021

I'm sorry, I got too focussed on understanding the problem, and then when I had, relating the solution back to the original question.

Your thinking is correct here, you will need to do this with custom fields.

The JQL functions are for searching, they do not apply to ordering.  The "order by" clause is not a part of a query, it is just a way to say "you should sort by this field" to any function that the search results are passed into (those functions actually do the sort, the query does not).

The sort is done by the function displaying the results, not by the query.  The issue navigator is only coded to take a field from the sort clause

So, the answer is no, you can't "order by function".  You have to do it by field.

Like Radek Janata likes this
Pablo
Contributor
February 3, 2021

Got it

 

Thank You for Your time :)

Suggest an answer

Log in or Sign up to answer