Automatically change priority based on due date

Paul Harman April 15, 2013

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

1 vote
Henning Tietgens
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 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

0 votes
Michal Husar
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 16, 2013
0 votes
Henning Tietgens
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 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
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 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.

Like Anna Kapitonova likes this
Paul Harman April 15, 2013

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?

Like Anna Kapitonova likes this
Paul Harman April 15, 2013

Thanks anyway. Will take a look for the groovy api

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 16, 2013

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.

Paul Harman April 16, 2013

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
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 16, 2013

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

Suggest an answer

Log in or Sign up to answer