Find issue links with both remote link and local instance links for an issue from the database
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
How to find issue links with both remote link and local instance links for an issue from the database.
Environment
8.20.x
Cause
At times, end users might miss certain issue links they believe should be linked to the issue they are viewing. There are rest endpoints to to get the Remote links and the local instance link separately. But not a single call to get both types of links together.
Solution
The following query can be utilized to gather all the issues and their related issues and their relation along with whether the relationship is local or remote link.
Postgres
1
2
3
4
5
6
7
with cte as (select ji.id as id, ji.project as project, ji.issuenum as issuenum, p.pkey as pkey from jiraissue ji join project p on p.id = ji.project)
select cte.id as id, cte.pkey || '-' || cte.issuenum as SrcIssueKey,Rl.Title as RelatedIssueKey,ilt.linkname as Relationship,'Remote' as Type from cte join remotelink rl on rl.issueid = cte.id join issuelinktype ilt on ilt.outward = rl.relationship
union
select cte.id as id, cte.pkey || '-' || cte.issuenum as SrcIssueKey,Dest.issuekey as RelatedIssueKey, ilt.linkname as Relationship,'Local' as Type from cte join issuelink il on il.source = cte.id join issuelinktype ilt on ilt.id = il.linktype join (select cte.pkey || '-' || cte.issuenum as issuekey, ill.linktype as linktyp, ill.source as sourceid from cte join issuelink ill on ill.destination = cte.id join issuelinktype ilt on ilt.id = ill.linktype) Dest on Dest.sourceid = il.source and Dest.linktyp = il.linktype
union
select cte.id as id, cte.pkey || '-' || cte.issuenum as SrcIssueKey,Source.issuekey as RelatedIssueKey, ilt.linkname as Relationship,'Local' as Type from cte join issuelink il on il.destination = cte.id join issuelinktype ilt on ilt.id = il.linktype join (select cte.pkey || '-' || cte.issuenum as issuekey, ill.linktype as linktyp, ill.source as sourceid from cte join issuelink ill on ill.source = cte.id join issuelinktype ilt on ilt.id = ill.linktype) Source on Source.sourceid = il.source and Source.linktyp = il.linktype
order by id;
Was this helpful?