Automatically change priority based on due date

Hi all,

How could I automatically change the priority of all issues where the due date is due in the next 2 weeks?

Could this be done through jelly somehow running on a service?

Thanks
Paul

3 answers

This widget could not be displayed.
Henning Tietgens Community Champion Apr 15, 2013

You can script a service using the Script Runner plugin which search for issues using e.g. a JQL search and update all found issues.

Or you could try to use jelly escalation like described here.

Henning Tietgens Community Champion Apr 15, 2013

I think it's possible, but I might not be the right one to help you with this. I tried Jelly at first but switched to Groovy via Script Runner because for me it's clearer how to use the API through Groovy.

Thanks. I did look at the escalation page, but it seems to use a transition to change the status, whilst I would just like to change the priority. Is this possible?

Thanks anyway. Will take a look for the groovy api

If you are using this: https://jamieechlin.atlassian.net/wiki/display/GRV/Escalation%20Service - you don't need to specify an action, just can just set the priority.

Ahh thanks guys. Used Jamie's way of doing it via the built in script, with some of Henning's code. How do I split karma?

Henning Tietgens Community Champion Apr 16, 2013

If you like comments, the commenter gets karma, too. :-)

This widget could not be displayed.
Henning Tietgens Community Champion Apr 16, 2013

You can use this script as a base for a Script Runner service.

package eventim.services

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Logger
import static com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH

Logger log = Logger.getLogger("EscalationService")

log.debug "Starting Escalation Service"

IssueService issueService = ComponentAccessor.issueService
user = ComponentAccessor.userUtil.getUserObject('jira_bot') // This has to be a user who has access to all issues

List<Issue> issues = getFilterResult("duedate < 14d AND priority not in (Blocker, Critical) and resolution = Unresolved", log, user)
log.debug "Found ${issues.size()} issues to raise priority."
issues.each {issue ->
    IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
    issueInputParameters.setPriorityId('2') // Critical
    validationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)

    if (validationResult.isValid()) {
        updateResult = issueService.update(user, validationResult, DO_NOT_DISPATCH, false)
        if (!updateResult.isValid()) {
            log.error "Update failed"
            updateResult.errorCollection.errorMessages.each {log.error "Error Message: $it"}
        } else {
            log.info "Update priority of issue with ID $issue.id"
        }
    } else {
        log.error "validationResult for ${issue.id} with user ${user} is not valid, not attempting update."
        validationResult.errorCollection.errorMessages.each {log.error "Error Message: $it"}
    }
}

List<Issue> getFilterResult(String jqlSearch, Logger log, User user) {
    SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
    List<Issue> issues = null

    SearchService.ParseResult parseResult =  searchService.parseQuery(user, jqlSearch)
    if (parseResult.isValid()) {
        def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
        issues = searchResult.issues
    } else {
        log.error("Invalid JQL: " + jqlSearch)
    }
    return issues
}

Have fun!

Henning

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

299 views 1 4
Join discussion

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