The Adaptavist Group LogoDocumentation

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 Issues from @scriptrunnerhq/hapi/issues.
  • Call Issues.transition inside your script's default async function.
  • 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 fields object 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.transition with 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 as resolution by passing a fields object as the third argument to Issues.transition.

Search documentation

Start typing to search the docs.