Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner - List of all linked issues in project

Qi Jiang
Contributor
April 10, 2018

I need to list all linked issues with in project AAA(Which created using jira service desk), in format of :

source issue id - issue summary    Links.

Got code below, but looks like msssing lots of links

import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.issue.link.IssueLinkManager;
import com.atlassian.jira.issue.link.LinkCollectionImpl;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.link.IssueLink;
import java.util.Collection;
import java.util.Iterator;
import org.apache.log4j.Logger;
import org.ofbiz.core.entity.GenericEntityException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

String projectKey = "AAA";

IssueManager issueManager = ComponentAccessor.getIssueManager();
Long projectId = ComponentAccessor.getProjectManager().getProjectByCurrentKey(projectKey).getId();
Collection<Long> issueIdsForProject = issueManager.getIssueIdsForProject(projectId);
int issuesInTransition = 0;
String results = "<h3><b>Issues under Project: " + projectKey + "</b></h3></br>";
results = results + "<table border=1><tr><th>Issue</th><th>Links</th></tr>";
for (Long issueId : issueIdsForProject) {
MutableIssue issue = issueManager.getIssueObject(issueId);

results = results + "<tr><td>" + issue.getKey() + " - " + issue.getSummary() + "</td><td>";
//Linked Issues
List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
String key = issueLink.getDestinationObject().getKey();
results = results + key + "(" + issueLink.getIssueLinkType().getName() + "), ";
}

results = results + "</td></tr>";
issuesInTransition++;

}
results = results + "</table><br/><b> No. of Lined Issues: " + issuesInTransition + "</b>";
return results;  

 

1 answer

1 accepted

0 votes
Answer accepted
Alexey Matveev
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 10, 2018

You get only outward links but there are also inward links. There must be 2 loops in your code one with outward links (you have it now) and the second one with inward links:

 List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.getId());
for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
IssueLink issueLink = (IssueLink) outIterator.next();
String key = issueLink.getSourceObject().getKey();
results = results + key + "(" + issueLink.getIssueLinkType().getName() + "), ";
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events