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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Ivan Tovbin I will give this a try as soon as my Staging server is available and post the results here. Cheers!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Ivan Tovbin that was the problem. I was not using the link name. I was using the name of the Outward link.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.