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

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

Avatar

1 badge earned

Collect

Participate in fun challenges

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

Challenges
Coins

Gift kudos to your peers

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

Recognition
Ribbon

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!

Leaderboard

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
4,466,928
Community Members
 
Community Events
176
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

Regards,

Marco

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,

Marco

Hi,

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

Thanks,

-Barb

@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")

if(linkedIssues){
return linkedIssues.size()
}else{
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:  https://docs.atlassian.com/software/jira/docs/api/7.1.4/com/atlassian/jira/issue/link/IssueLinkManager.html

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 https://docs.atlassian.com/software/jira/docs/api/7.1.4/com/atlassian/jira/issue/link/LinkCollection.html where it does use the name.   

 

Thanks for your help,

-Barb

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
TAGS

Atlassian Community Events