Skip to main content
Skip table of contents

Show Related Issues in a Separate Column

The following two scripts can be used to work with issues on two separate instances connected with an App Link. It adds a field to the issue that shows all the issues that are linked through any issue link type. The first script does this purely for issues that are on a linked, but separate, Jira instance (like a Service Management / Service Desk instance and a Dev instance, for example). The second script does the exact same thing for all linked issues on the same instance.

In order to run these scripts, there are a few preconditions that need to be met. You will need to create a scripted field and set it to an HTML template.

Script 1

This script identifies issues on a separate Jira instance that have an issue link connecting them to any issues on this instance.

Be aware that in order for this script to work, these instances will need to be connected through an Application Link and the user running these scripts will need Jira administrator privileges on both instances.

GROOVY
package com.onresolve.jira.groovy.test.scriptfields.scripts

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.RemoteIssueLinkManager

def remoteLinkManager = ComponentAccessor.getComponent(RemoteIssueLinkManager)

def startHTML = '<a href="'
def endHTML = '">'

def remoteIs = remoteLinkManager.getRemoteIssueLinksForIssue(issue)
def remIs = new String[remoteIs.size()]
def count = 0
remoteIs.each {
    remIs[count] = startHTML + it.getUrl() + endHTML + it.getTitle() + '</a>'
    count++
}
remIs
?:null

Script 2

This script will add a field to each issue that shows all the linked issues on this same instance.

GROOVY
package com.onresolve.jira.groovy.test.scriptfields.scripts

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager

def linkManager = ComponentAccessor.getComponent(IssueLinkManager)

def startHTML = '<a href="'
def baseUrl = 'http://myjirainstance.com/browse/'
def endHTML = '">'

def issueLinks = linkManager.getIssueLinks(issue.id)
def remIs = new String[remoteIs.size()]
def count = 0
def otherIssue
issueLinks.each {
    if( issue.id == it.id ){
        otherIssue = it.getDestinationObject()
    } else {
        otherIssue = it.getSourceObject()
    }
    remIs[count] = startHTML + baseUrl + otherIssue.getKey() + endHTML + otherIssue.getKey() + '</a>'
    count++
}
remIs
?:null

You should replace the value in `baseUrl` with the actual URL of your local instance.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.