Work with Links
Learn how to create and remove links of any type between two work items using Issues.linkIssue and Issues.unlinkIssue.
Pattern for working with links with HAPI
When you work with links, you can follow this basic pattern:
- Import
Issuesfrom@scriptrunnerhq/hapi/issues. - Use
Issues.linkIssueto create a link between two work items. - Use
Issues.unlinkIssueto remove an existing link. - Provide:
- The source work item key.
- The link type name (for example,
"Blocks"). - The target work item key.
The following example shows this general pattern:
import * as Issues from '@scriptrunnerhq/hapi/issues'
export default async function () {
// Create a link of a given type between two work items
await Issues.linkIssue('SOURCE_KEY', 'Blocks', 'TARGET_KEY')
// Later, remove the same link if needed
// await Issues.unlinkIssue('SOURCE_KEY', 'Blocks', 'TARGET_KEY')
}In-app example scripts
The following examples are available in-app:
- Link work items: Shows how to use
Issues.linkIssueto create a work item link of a given type (for example,"Blocks") between two work items. - Unlink work items: Shows how to use
Issues.unlinkIssueto remove an existing work item link of a given type between two work items.