Cannot extract IssueLink from issue

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!

 

Issue01.pngIssue02.png

1 answer

1 accepted

2 votes

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") 

Hi Tarun,

thank you very much for your quick respond. You are right - that was the problem - now it's solved! :)

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

134 views 4 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you