Transition Work Items
With HAPI, you can move work items through their workflow by triggering transitions. This page walks you through transitioning work items using HAPI’s Issues.transition function.
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 key.
- The transition name (as configured in your Jira workflow).
- Optionally provide a
fieldsobject to update fields as part of the transition (for example, setting a resolution).
The following example shows this general pattern:
typescriptimport * 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 // }, // }) }
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 script 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.