Jira Agile: modify Issue rank on creation using the groovy script runner

Stefano Luperto April 7, 2014

If an issue in the Agile backlog is selected, a new issue is ranked just after the selected one, while I would like to rank it always last.

I've tried to use the code suggested in this answer:

https://answers.atlassian.com/questions/73449/using-the-greenhopper-api-to-modify-rank

except I use:

def outcome = rankService.rankLast(user, rankField.getIdAsLong(), issue);

When I add the script postfunction on the Create transition (after the fire issue event), it does not work. The newly created issue is ranked just below the selected one and not as last.
If I add the same postfunction to another transition, the issue is moved to the lowest rank in the backlog. So the code works, the problem is just on creation.
So I've tried a trick: I've added the postfunction to a "loop" transition (hidden to users) and after creation I FastTrack the issue through this transition. When I test this on my development pc the trick works. But after installing it on production the issue stays below the selected issue.
I've tried to:
  • add an explicit issue reindex after calling the ranking service
  • use a listener instead of a postfunction
  • dispatch a new event after calling the ranking service

but nothing worked.

Any idea why the script on the create transition does not work in any case and why if fasttracking to another transition after creation it works on testing and not on production?

I guess it's somehow a timing issue (ranklast happening before the board modifies the rank to place it after the selected issue), but how to work around this?

Thank you

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Stefano Luperto April 7, 2014

Hi Jamie, thank you for your suggestion (and for the plugin, that's great!).

I've tried to call the ranking service in a different thread and it works but I still have a problem. The issue is updated but the Agile board is not. If I refresh the page I can see the issue moved to the bottom, so code it's fine, but unless the user hits the refresh button on the browser he will continue to see the issue in the old position.

If the user then creates a second issue, Agile somehow understands that something changed and reloads the boad, so both are shown in the right place. That's a bit confusing for the end user.

It would be better to force a board update after the first issue creation. I've found this:

https://jira.atlassian.com/browse/GHS-4452

so maybe in the future the auto-refresh will be extended to the plan view as well. Any suggestion in the meantime?

JamieA
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 7, 2014

Yeah... I don't see what you can do about the page refresh issue. I think as you say the issue is that GH ranks the issue after the current, after your code runs if you don't add a delay. If you do add a delay, the page view is out of date.

0 votes
JamieA
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 7, 2014

I would not use a fast-track transition - it's not the right way to solve this problem imho.

You could try doing it in another thread with a short delay:

Thread thread = new Thread(new Runnable() {
    void run() {
        Thread.sleep(1000)
        // do your stuff
    }
})
thread.start()

The next version aims to make this kind of thing a bit easier.

As to why it's not working in prod, most probably a misconfiguration. Add some debug, check the logs...

TAGS
AUG Leaders

Atlassian Community Events