Simple Escalation

JIRA as a Support System

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

Here is a piece of code that performs simple escalation. The code finds all issues that have been in the 'Open' status for longer than 24 hours and increases the priority of these issues (if there is a higher priority). This code could be used in a JIRA service so that it is performed periodically.

Please note that the code assumes that all the issues use the default workflow. Hence it also assumes that the the step id it should search for in the OSCurrentstep table is 1. If your issues are using a different workflow you will need to see what status id to search for.

        EntityCondition con = new EntityExpr(
        new EntityExpr("stepId", EntityOperator.EQUALS, new Long(1)),
        EntityOperator.AND,
        new EntityExpr("startDate", EntityOperator.LESS_THAN_EQUAL_TO, new Timestamp(System.currentTimeMillis() - 24*3600*1000))
);

List steps = CoreFactory.getGenericDelegator().findByCondition("OSCurrentStep", con, null, null);
for (Iterator iterator = steps.iterator(); iterator.hasNext();)
{
    GenericValue stepGV = (GenericValue) iterator.next();
    IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
    GenericValue issueGV = issueManager.getIssueByWorkflow(stepGV.getLong("entryId"));

    // Increase priority
    ConstantsManager constantsManager = ComponentManager.getInstance().getConstantsManager();
    GenericValue priority = constantsManager.getPriority(issueGV.getString(IssueFieldConstants.PRIORITY));
    Collection priorities = constantsManager.getPriorities();
    GenericValue higherPriority = null;
    for (Iterator iterator1 = priorities.iterator(); iterator1.hasNext();)
    {
        GenericValue priorityGV = (GenericValue) iterator1.next();
        if (priorityGV.getString("id").equals(priority.getString("id")))
        {
            if (higherPriority != null)
            {
                // Update issue
                issueGV.set(IssueFieldConstants.PRIORITY, higherPriority.getString("id"));
                // Save issue to database and fire an event
                GenericValue originalIssue = issueManager.getIssue(issueGV.getLong("id"));
                User updater = UserUtils.getUser("admin");
                IssueUpdateBean issueUpdateBean = new IssueUpdateBean(issueGV, originalIssue, IssueEventType.ISSUE_UPDATED, updater);
                IssueUpdater issueUpdater = ComponentManager.getInstance().getIssueUpdater();
                issueUpdater.doUpdate(issueUpdateBean, true);

            }

            break;
        }
        else
        {
            higherPriority = priorityGV;
        }
    }
}

The above code will make change items of updated issues appear as if they have been performed by the "admin" user. You may wish to create a special user for this task.

Last modified on Jun 15, 2009

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.