Forums

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

How to sort backlog items using a scrypt?

Mariusz Bakalarz August 3, 2022

I am working on a project where we would like to be able to automatically sort the backlog items (and I don't mean filtering them). I have no experience in JQL scripts but I know a scrypt can be utilized to sort the backlog automatically (for example every 24 hours). 

What we want to achieve is to sort the items based on priority (in the easiest scenario). If possible, we want to be able to sort things by more complex conditions and levels, i.e. firstly sort them by the release number, then within those releases sort them by epic links and further within those, sort them by their priority.

Anyone can help with that? :D

3 answers

0 votes
Sergey Gradovich August 3, 2022

If the question is on how to code JQL to filter out using different fields you can try something like this:

project = XYZ order by Rank asc, Priority asc, createdDate desc

Mariusz Bakalarz August 3, 2022

Questions is not about filtering but creating a scrypt to automatically sort the backlog items (automate a manual process of moving items around).

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.
August 3, 2022

Welcome to the Atlassian Community!

You would need to build a REST API script that re-ranks your backlog in batches of 50, via https://developer.atlassian.com/cloud/jira/software/rest/api-group-issue/#api-rest-agile-1-0-issue-rank-put

I would very strongly recommend that you never do this.  You are destroying the ranking your users have done in their backlogs, rendering the whole backlog functionality utterly pointless, and removing your team's ability to be in the slightest bit agile, because you're micro-managing them (and automating it!).

If you really want to have something that sorts your issues this way and can then be used to inform backlog refinement (not do it, just inform it), then I would 

  • Take a copy of the board filter (let's say it is currently "project in (ABC, DEF) order by rank")
  • Exclude done items
  • Exclude active items (because you don't need these to inform your planning)
  • Add your sorting to it
  • Give it to the users as a saved filter, or even better, present it on a shared dashboard.

project in (ABC, DEF) and status not in (in-progress, done) and sprint not in sprint in futureSprints() and sprint not in openSprints() order by Priority, release, epic-link

You won't need to code anything, and the filter is dynamic, so you don't need to run it periodically.

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.
August 3, 2022

Bother, I forgot.

If you genuinely want to dump the backlog ranking functions, and treat it as though it is a queue, then it's actually quite simple.

Change the board filter from ending with "Order by rank" to "order by priority, release, epic-link".

There's no need to run a sort that way, it'll always be in the right order.

Mariusz Bakalarz August 3, 2022

Hi @Nic Brough -Adaptavist- thank you for that answer. The thing is that this sorting is suppose to help the PO in managing the Product Backlog. 

We do not want to turn the ranking system off, as we want to keep the dragging and dropping functionality. 

Sergey Gradovich August 3, 2022

@Mariusz Bakalarz in the Jira board you could either have sorting by rank and having ability to dragging tickets or via sorting by different fields, but you will lose ability to prioritize things over dragging stuff around.

Mariusz Bakalarz August 4, 2022

That's something different. I want to introduce a scrypt to the Jira board that will automatically sort the items (like every 24h or by some kind of trigger) by specified conditions. This solution doesn't need changing the sorting by rank option.

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.
August 4, 2022

Ok, this is a direct contradiction:

"... sort the items ... This solution doesn't need changing the sorting by rank option."

The rank is the sort order.  If you sort the issues in your backlog, then you're re-ranking them.

If I've misunderstood your requirement here, could you explain more?

Mariusz Bakalarz August 4, 2022

Order by ranking allows users to drag and drop items in the backlog. Order by priority denies that action, is that correct?

To reinstate - we want to have a scrypt that will automatically sort the backlog items by given conditions (in order by: epic links -> sprints -> priority), like every 24h or by some sort of trigger and at the same time if the scrypt is not triggered, allow users to move the items around by themselves. 

Sorry if that is confusing.

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.
August 5, 2022

The requirement is technically clear, but I think I am confused on why you would want to do it this way.

Let me try to explain what the implications of this are with an example.  Imagine you have 8 issues in your backlog today, and you run your sort at 8am, ending up with a backlog that looks like:

  • AA-1
  • AA-3
  • AA-5
  • AA-7
  • AA-4
  • AA-2
  • AA-6
  • AA-8

Your team arrives for work, does some refinement on the backlog, dragging AA-1 and AA-3 into the next sprint, and notices that AA-5 is dependent on AA-6 being done first, so the backlog becomes:

  • AA-1
  • AA-3
  • ----(marker for where things are in the next sprint)
  • AA-6
  • AA-5
  • AA-7
  • AA-4
  • AA-2
  • AA-8

They continue work on the current sprint.

When they come in tomorrow, your script will have destroyed all their refinement, reverting to the first list.

Are you really saying you want to reset the backlog to your order every day?

Mariusz Bakalarz August 5, 2022

True that is a good observation. Continuing this example, we would like to sort the backlog automatically and get the order you presented:

  • AA-1
  • AA-3
  • AA-5
  • AA-7
  • AA-4
  • AA-2
  • AA-6
  • AA-8

Then continue with refinement and manual ordering of the items:

  • AA-1
  • AA-3
  • ----(marker for where things are in the next sprint)
  • AA-6
  • AA-5
  • AA-7
  • AA-4
  • AA-2
  • AA-8

And at this point, stop the automated sorting scrypt until it will be needed further in the future. Is it possible to trigger the sorting not daily but for example somehow manually?

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.
August 6, 2022

You should be able to run a script whenever you like, but that depends on how you  are writing it.

But I'd suggest thinking through when you might want to run it.  It's only actually of any use when you have an existing backlog that was not doing any useful form of prioritisation and you've decided to start again because your people have made a hash of it.

Once you've run it and reset the backlog to derived order, then your people will start backlog refinement and never want to use it again.  It would be far easier for to say "well, your backlog is a bit of a mess, let's dedicate half an hour to identify what big/urgent items are in the wrong place and fix them", rather than destroying the whole thing and starting from scratch.

Mariusz Bakalarz August 8, 2022

Yes that is mostly correct. The thing is I don't know how to create such a script (I have no experience in this 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.
August 8, 2022

You'll need to pick a language you can write a script or program in, one that can make REST calls and work with the responses. 

You'll then need to code for something to iterate through your backlog, maybe reading the whole thing, working out an order and then applying it (in batches of 50 because that's what the API is limited to)

Seriously, for something you're only going to run once, that's a lot of work. 

Sergey Gradovich August 8, 2022

JIRA Cloud will return items in batches of 100 (see https://jira.atlassian.com/browse/JRACLOUD-67570).

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.
August 8, 2022

Sorry, looks like the docs have not been updated to say 100 instead of the old 50.

0 votes
Sergey Gradovich August 3, 2022

Not sure it's possible. But I'm subscribing for this thread. :) 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events