Transition Work Items
Learn how to move work items through their workflow with Issues.transition, using a transition name or ID, and set fields such as Resolution.
Pattern for transitioning work items with HAPI
When you transition a work item with HAPI, you can follow this basic pattern:
- Import
Issuesfrom@scriptrunnerhq/hapi/issues. - Call
Issues.transitioninside your script's defaultasyncfunction. - Provide:
- The work item, as either its key or a work item you have already fetched.
- The transition, as either its name (as configured in your Jira workflow) or its ID.
- Optionally provide a
fieldsobject to update fields as part of the transition (for example, setting a resolution).
The following example shows this general pattern:
import * as Issues from '@scriptrunnerhq/hapi/issues'
export default async function () {
// Perform a simple workflow transition by name
await Issues.transition('WORKITEM_KEY', 'Start Progress')
// Or, perform a transition and update fields at the same time:
// await Issues.transition('WORKITEM_KEY', 'Resolve Issue', {
// fields: {
// resolution: { name: 'Done' },
// // You can set other fields here if required by the transition
// },
// })
}If your script has already fetched the work item, pass it straight to Issues.transition instead of its key:
import * as Issues from '@scriptrunnerhq/hapi/issues'
export default async function () {
const workItem = await Issues.getByKey('WORKITEM_KEY')
if (!workItem) return
await Issues.transition(workItem, 'Pending')
}You can use the same Issues.transition pattern to move a work item between workflow states by name, or satisfy transition requirements by setting fields (such as resolution) in the same call.
In-app example scripts
The following examples are available in-app:
- Transition a work item: Shows how to call
Issues.transitionwith a work item key and a transition name (for example,"Start Progress") to move a work item to the next workflow state. - Transition a work item with field updates: Shows how to execute a transition (for example,
"Resolve Issue") and simultaneously update fields such asresolutionby passing afieldsobject as the third argument toIssues.transition.