How to count the number of issue links of an inssue

Thuy Mai March 17, 2014

Hi

I want to create a custom field to display the number of issue links of an issue. How should i do that ?

Thanks

7 answers

1 accepted

1 vote
Answer accepted
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 17, 2014

You can create a Script Runner Scripted Field.
The script for the field will look like:

import com.atlassian.jira.component.ComponentAccessor
a = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, issue.reporter).getAllIssues().size()
a.toString()

More info on scripted fields:

https://jamieechlin.atlassian.net/wiki/display/GRV/Scripted+Fields

Thuy Mai March 25, 2014

Thanks for your suggestion. I gave it a try but it does not work. Could you please help provide more detail steps ? Sorry i'm new to Jira

Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 2, 2014

Which part did not work ?

Is the field shown with wrong value or it is not there at all ?

A June 22, 2015

Hi Boris, I needed to count specific type of linked issues. Ex:- issue has 2 type of linked issues, 2 linked as blocks and 2 linked as clone. How can i get these separately. Current answer is 4, but i need 2

Marie Goodart May 24, 2017

Variable [a] is undeclared is the error

1 vote
Onkar Ahire
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 17, 2014

Hi Thuy Mai,

Try Database Value plugin and select count(*) from issuelink whereSOURCE=(selectid fromjiraissue wherepkey='${jira.issue.key}')

or

https://answers.atlassian.com/questions/215718/scripted-field-to-return-number-of-cloned-issues-not-workingscripted field will help you most rather than DB value plugin.

I think its little bit closer to your requirement.

Cheers

0 votes
Vijay Akula June 7, 2021

Hi - does anyone have a script sample for the cloud version? Thanks!

0 votes
Philippe Puy July 17, 2018

Worked with a slight modification of Boris script:

import com.atlassian.jira.component.ComponentAccessor
def CountLink = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, issue.reporter).getAllIssues().size()
CountLink.toString()
Michael September 5, 2019

Amazing, thank you :) 

Kris Han January 20, 2020

Hi @Philippe Puy ,

I faced a problem for this script. Do you know how to count the number of linked issues base on linked issues type? Thank you very much!

0 votes
Thuy Mai April 2, 2014

It works now. Thanks

0 votes
Onkar Ahire
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 17, 2014

Hi Thuy Mai,

Try Database Value plugin and select count(*) fromissuelink.

I think its little bit closer to your requirement.

Cheers

0 votes
Onkar Ahire
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 17, 2014

Hi Thuy Mai,

Try Database Value plugin and select count(*) fromissuelink.

I think its little bit closer to your requirement.

Cheers

Suggest an answer

Log in or Sign up to answer