How to move bugs to top of backlog after creation with scriptrunner?

Is there a way to move issues with the issue type "bug" to the top of the backlog (Kanplan planning mode) programmatically using scriptrunner, after creation?

1 answer

This widget could not be displayed.

Yup! By updating the Rank custom field. To do that, you need to access the Jira Software (formerly known as Agile, formerly known as Greenhopper...) API.

import com.atlassian.greenhopper.api.rank.RankService
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.pyxis.greenhopper.jira")
@JiraAgileBean RankService rankService
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def customFieldManager = ComponentAccessor.customFieldManager
def rankField = customFieldManager.getCustomFieldObjects(issue).find{it.name == "Rank"}
rankService.rankFirst(currentUser, rankField.idAsLong, issue)

Thanks for the code. I implemented it as a Script Listener after an issue has been created. It gets executed without errors, but when I switch back to the Backlog, Bugs (Defects) are still at the bottom.

 

Screen_Shot_2017-11-20_at_10_44_01.png

It may be failing silently. Perhaps we just need to add some error handling so you get appropriate logs:


import com.atlassian.greenhopper.api.rank.RankService
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.pyxis.greenhopper.jira")
@JiraAgileBean RankService rankService
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def customFieldManager = ComponentAccessor.customFieldManager
def rankField = customFieldManager.getCustomFieldObjects(issue).find{it.name == "Rank"}
def outcome = rankService.rankFirst(currentUser, rankField.idAsLong, issue)
if (outcome.isValid()) {
log.debug "Updated issue rank"
} else {
log.warn outcome.warningCollection?.warnings
log.error outcome.errorCollection?.errorMessages
}

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Apr 22, 2018 in Jira Software

How-to setup a secured Jira Software 7.9.0 on Ubuntu 16.04.4 in less than 30 minutes

...PermissionsStartOnly=true User=www-data Group=www-data ExecStart=/opt/jira/bin/startup.sh ExecStop=/opt/jira/bin/shutdown.sh TimeoutStartSec=120 TimeoutStopSec=600 PrivateTmp=true [Install] WantedBy...

1,478 views 10 12
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you