Hi,
I have 2 Jira instances (01 & 02) which are linked. Each instance contains an issue (TEST01-1 & TEST02-1). The issues are linked to each other (reciprocal link). My goal is to extract TEST01-1 from the link in TEST02-1, therefore I have written the following code:
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def allRelatedIssues = new LinkedList<Issue>()
for (IssueLink link in issueLinkManager.getOutwardLinks((Long)10400)) {
allRelatedIssues.add(link.getDestinationObject())
}
log.debug ('Size of Issue-List: ' + allRelatedIssues.size())
log.debug ('Content of Isse-List: ' + allRelatedIssues)
log.debug ('Size of IssueLink-List Outward: ' + issueLinkManager.getOutwardLinks((Long)10400).size())
log.debug ('Size of IssueLink-List Inward: ' + issueLinkManager.getInwardLinks((Long)10400).size())
log.debug ('Issue-Key for the Issue-ID 10400: ' + ComponentAccessor.issueManager.getIssueObject(10400 as long))
When I execute the code in the Script console I obtain the following output:
2017-11-10 15:51:29,780 DEBUG [groovy.PostFunction]: Size of Issue-List: 0
2017-11-10 15:51:29,780 DEBUG [groovy.PostFunction]: Content of Isse-List: []
2017-11-10 15:51:29,780 DEBUG [groovy.PostFunction]: Size of IssueLink-List Outward: 0
2017-11-10 15:51:29,780 DEBUG [groovy.PostFunction]: Size of IssueLink-List Inward: 0
2017-11-10 15:51:29,781 DEBUG [groovy.PostFunction]: Issue-Key for the Issue-ID 10400: TEST01-1
As the output indicates, the List "allRelatedIssues" is empty and I don't understand why. After all, the Issues are linked, I used the right Issue-ID (see Screenshots) and I performed a re-index just in case. What could be the problem? Does anybody have an idea?
Thank you in advance!
It seems you have "remote links" in your issues instead of normal issueLinks. Thus "issueLinkManager" won't work as it's for internal links within the same JIRA instance but you have 2 different JIRA instances.
Try this code snippet
RemoteIssueLinkService remoteIssueLinkService = ComponentAccessor.getComponent(RemoteIssueLinkService.class)
RemoteIssueLinkService.RemoteIssueLinkListResult links = remoteIssueLinkService.getRemoteIssueLinksForIssue(currentUser, issue
(you have to use "RemoteIssueLinkService")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.