Escalation Service
The Escalation Service allows you to define a process for modifying issues after a certain amount of time has elapsed. This is useful for business procedures that require tasks to be completed within a certain time-frame (service level agreement). For example, if a task has been opened but not assigned for 7 days you could automatically move it to a "Prioritise" status, or add a comment which will cause an email to be sent.
You can configure a job to run in the same way you can configure Scheduled Jobs.
Note
|
The minimum interval between code executions is 1 hour. The scheduler is triggered every hour and gathers all the tasks to be executed within that hour. The task executions are queued and workers will consume them in no predefined order. That means that the execution time of the task can not be guaranteed to be the same every hour. As an example: if you configure a job to be run every hour, it might be run at 01:02 and then 02:24 and then 03:00 and then at 04:46 etc depending on how busy our systems are. |
Each defined job must have a JQL query that will be run in order to find the issues you wish to modify. The code you provide as part of the job configuration will be run against each issue individually, and in parallel. Each issue will be injected into your code as part of the Script Context.
Note
|
The maximum number of issues you can modify in any execution of an Escalation Service job is 50. In other words, we limit the number of issues returned by each JQL query to 50 issues. |
The schedule editor dialog lets you choose between running your script on several days during the week (e.g. Monday, Wednesday, Friday), or running your script on particular days of the month (e.g. the last day of the month, the 2nd Tuesday of the month). Additionally you can select an hour interval during which your script will be run.
Each Escalation Service job can execute for the same length of time as Script Listeners, Post Functions and in the Script Console as documented here.
There is a possibility to test your script using "Run Now" button that will execute the jql and perform the script. The results of the run and logs are displayed per each issue.
Samples
Take one of these samples and use it as a starting point for your own needs.
Flag an Issue
This example shows how you can flag the Issues returned by the JQL search which is run at a specified time.
In order to use this example you will need to paste the example code below inside of the code box as well as to specify the JQL Query to search for the issues to update, along with the schedule of when this escalation service should run.
// Look up the custom field ID for the flagged field
def flaggedCustomField = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == 'Flagged'
} as Map
// Update the issue setting the flagged field
def result = put("/rest/api/2/issue/${issue.key}")
.header('Content-Type', 'application/json')
.body([
fields:[
// The format below specifies the Array format for the flagged field
// More information on flagging an issue can be found in the documentation at:
// https://confluence.atlassian.com/jirasoftwarecloud/flagging-an-issue-777002748.html
(flaggedCustomField.id): [ // Initialise the Array
[ // set the component value
value: "Impediment",
],
]
]
])
.asString()
// Check if the issue was updated correctly
// Log out the issues updated or which failed to update
if (result.status == 204) { (11)
logger.info("The ${issue.key} issue was flagged as an Impediment. ")
} else {
logger.warn("Failed to set the Impediment flag on the ${issue.key} issue. ${result.status}: ${result.body}")
}
// Add a return message to show which issues the escalation service ran on.
return "Escalation Service completed on ${issue.key}"
Transition an Issue
This example shows how you can automatically transition the Issues returned by the JQL search which is run at a specified time.
In order to use this example you will need to paste the example code below inside of the code box as well as to specify the JQL Query to search for the issues to update, along with the schedule of when this escalation service should run.
// The ID of the workflow transition to execute.
// Note - The transition ID must represent a valid transition for the workflow that the issue uses.
def transitionID = '<TransitionIDHere>'
// The rest call to transition the issue
def result = post("/rest/api/2/issue/${issue.key}/transitions")
.header("Content-Type", "application/json")
.body([transition: [id: transitionID]])
.asObject(Map)
// Check if the issue was transitioned correctly
// Log out the issues updated or which failed to update
if (result.status == 204) {
logger.info("The ${issue.key} issue was transitioned by the escalation service.")
} else {
logger.warn("The escalation service failed to transition the ${issue.key}issue. ${result.status}: ${result.body}")
}
// Add a return message to show which issues the escalation service ran on.
return "Escalation Service completed on ${issue.key}"