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

How to get Linked issues of an issue using API

Srinivas Patruni July 24, 2013

I searched the issue object but i did not find any method which returns list of linked issues of an issue. How can we get that?

4 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
RambanamP
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.
July 24, 2013

try with the following codefor Outward links

List<IssueLink> allOutIssueLink = ComponentAccessor.getIssueLinkManager().getOutwardLinks(sourceIssue.getId());
	for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) {
		IssueLink issueLink = (IssueLink) outIterator.next();
			if (issueLink.getIssueLinkType().getId() == linkId) {
				String key = issueLink.getDestinationObject().getKey();
			}
}

Same way you can do it for inward links

shashank_shekhar August 8, 2014

I get a null list when I try this, the Issue instance is not null and the issue has a link that I added my self.
I am triggering the method when the issue is modified.

0 votes
Vevin Kumar September 2, 2015

Below is the Script to list Open Issues and Issue Links in a Project. You need to run it on the JIRA Script Console plugin.

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 = "RFD";
String transitionStatus = "Open";
IssueManager issueManager = ComponentAccessor.getIssueManager();
Long projectId = ComponentAccessor.getProjectManager().getProjectByCurrentKey(projectKey).getId();
Collection<Long> issueIdsForProject = issueManager.getIssueIdsForProject(projectId);
int issuesInTransition = 0;
String results = "<h3><b>Open 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);
   if (issue.getStatusObject().getName().equals(transitionStatus)) {
      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 Open Issues: " + issuesInTransition + "</b>";
return results;

Hope this helps!!

0 votes
Paresh Gandhi
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.
August 8, 2014
import com.atlassian.jira.ComponentManager
import groovy.xml.MarkupBuilder
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ManagerFactory
import static org.apache.log4j.Level.DEBUG
import org.apache.log4j.Category
import org.apache.log4j.Level
import org.apache.log4j.Category
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import org.apache.log4j.Logger
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.LinkCollectionImpl

class CloseParentIssue extends AbstractIssueEventListener {
    Logger log = Logger.getLogger(CloseParentIssue.class)    
	@Override
    void workflowEvent (IssueEvent event) {
		log.setLevel(org.apache.log4j.Level.DEBUG)
		def itsdIssue
		Issue issue = event.getIssue()
		def issuestatus = issue.getStatusObject().getName().toUpperCase()
		def issueType = issue.issueTypeObject.name
		if (issuestatus == "CLOSED" && issueType == "New Feature" ) {
			def componentManager = ComponentManager.getInstance()
			def issueLinkManager = componentManager.getIssueLinkManager()
			def allLinkedIssueClosed = false				
			def itsdFound = false
			
			JiraAuthenticationContext authContext = ComponentAccessor.getJiraAuthenticationContext()
			User user = authContext.getLoggedInUser()
			
			allLinks  = issueLinkManager.getAllIssues()
			log.debug "size:" + allLinks.size
			issueLinkManager.getAllIssueKeys(issue.id).each {issueLink ->	
				log.debug "i'm in"
				def linkedIssue = issueLink.sourceObject
				String linkedIssueTemp = linkedIssue.key				
				if(linkedIssueTemp.contains("TEST")){
					itsdFound = true
					itsdIssue = linkedIssue
					log.debug "itsdFound" + itsdFound
				}		
				log.debug linkedIssue.key
				if(linkedIssueTemp.contains("TEST") == false) {
					if (linkedIssue.getStatusObject().getName().toUpperCase() == "CLOSED" ) {
						allLinkedIssueClosed = true			
					}
					else {
						allLinkedIssueClosed = false
					}
				}
				log.debug "	allLinkedIssueClosed " + allLinkedIssueClosed			
			}
			if(itsdFound)
				if(allLinkedIssueClosed){
					log.debug "I'm closing this issue"
				}
		}		
	}
}

above code may help

0 votes
Bhushan Nagaraj
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.
July 24, 2013

Hi Srinivas,

You need to use the IssueLinkManager. See the API here

https://developer.atlassian.com/static/javadoc/jira/5.0.5/reference/com/atlassian/jira/issue/link/IssueLinkManager.html

Let me know if you need further help I can send you some sample code.

Cheers

Bhushan

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events