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?
Community moderators have prevented the ability to post new answers.
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Srinivas,
You need to use the IssueLinkManager. See the API here
Let me know if you need further help I can send you some sample code.
Cheers
Bhushan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.