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?


3 answers

0 vote
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: - 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. :-)

0 vote
Henning Tietgens Community Champion Apr 16, 2013

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


import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.bc.issue.IssueService
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,, 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 {
   "Update priority of issue with ID $"
    } else {
        log.error "validationResult for ${} 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 =, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
        issues = searchResult.issues
    } else {
        log.error("Invalid JQL: " + jqlSearch)
    return issues

Have fun!


Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

73 views 0 5
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