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 votes
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 votes
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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,878 views 12 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot