Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Scripted field - count links from specific issue type

Hi All,

I am trying to count the number of linked issues of a specific issue type. (e,g, issuetype Bug has x linked Patches)

All the examples I have found so far are counting the linktype which is not working for us (inconsistency in use by the users) 

Does anybody have a sample script for scriptrunner that will do the trick?

Thanks in advance



1 answer

1 accepted

1 vote
Answer accepted

Hi Marco,

So basically you want to get the number of linked 'Bugs', yes?

Here's how you do it:

import com.atlassian.jira.component.ComponentAccessor

int x = 0
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def linkedIssues = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, currentUser).getAllIssues()
if (linkedIssues.size() > 0){
for (int i = 0; i < linkedIssues.size(); i++){
if (linkedIssues[i].getIssueType().getName() == "Bug"){
x = x + 1
if (x > 0){
return x
}else return null

Hi Ivan,

Thank you very much works like a charm.

Kind regards,



How can this be modified to get the count of Linked Issues with a specific link type rather than a specific issue type?



@Barb O'Connell

Try this:

import com.atlassian.jira.component.ComponentAccessor

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def linkedIssues = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, currentUser).getInwardIssues("linkName")

return linkedIssues.size()
return null

Depending on the link direction you need, you might wanna change 'getInwardIssues' to 'getOutwardIssues' 

Thank you @Ivan Tovbin I will give this a try as soon as my Staging server is available and post the results here.  Cheers!

Hi @Ivan Tovbin, sorry it did not work for me.  It always completes successfully with NULL value, even though I have linked issues.  I chose a simple issue link type like "blocks" which is inward (and I even tried with outward just in case).  Same results.

I don't know much about groovy, so I attempted to lookup what getInwardLink expects as an argument:

Looks like it wanted a sourceIssueId.  Am I reading that correctly?  Should I use something like getIssueLinks which takes the Issue Link Type Id as an argument, then I can use the specific linkt ype ID?

Maybe instead of

def linkedIssues = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, currentUser).getInwardIssues("linkName")

Is this a possibility?

def linkedIssues = ComponentAccessor.getIssueLinkManager().getLinkCollection(issue, currentUser).getIssueLinks("10020")


Note: I also see getInwardLink on where it does use the name.   


Thanks for your help,


Hi @Barb O'Connell,

I've just checked this in my test instance and it works just fine. I think the problem is that you are using link direction names (i.e. "clones" or "is cloned by") instead of link names (i.e. "Cloners" (case sensitive)). To get the link names go to Admin -> Issues -> Issue linking.

On a side note, getInwardIssues() method works perfectly fine here, as it returns you a collection of issues, if any, which are linked using the link, which name you pass as an argument, or an empty collection, if no such issues are found. Same goes for getOutwardIssues(). After that you simpy need to count the elements in this collection, hence the size() method is used.

Hope this helps.

Thank you @Ivan Tovbin that was the problem. I was not using the link name.  I was using the name of the Outward link.

@Ivan Tovbin 

The above script works fine,


could you add a script to validate all the stories in EPIC are closed

and then end date field to be updated to EPIC from STORY.

 @Ivan Tovbin

My project Bugs were linked in stories and requirement issue types with defined Epic , 

So i need consolidated linked bug count in EPIC level . 

For example ,

Requirement => has bug linked count 3

story => has bug linked  count 5 

Epic => has to be with bug linked count 8 


It could be helpful , if you share your code . 


Thank you in advance . 

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events