Sync remote links (for example: links to Confluence pages)

Redirected from Exalate Support:

I have a connection that sync issues between Jira Software and Jira Service Management, both of them Data Center.

When I add a Confluence page as a remote link in Jira Software, I want the connection to add the same remote link in the remote issue in Jira Service Management. For Example:

I search the documentation, and only found an old post that show how to sync the confluence links in a custom field. I want to sync the confluence links directly as native links, as you can see in the screenshot. There is a method in the nodeHelper that list the remote issue links: nodeHelper.getRemoteIssueLinks, but I don’t know if that method returns the Confluence page links. And I don’t know how to SAVE the links in the Incoming script in Jira Service Management.

Hi and welcome to the Exalate Community!

Thanks for sharing your question or insight, we appreciate your contribution.

A member of the Exalate team or community will review this post and respond as soon as possible.

In the meantime, feel free to explore related topics or join other conversations. We’re glad to have you here!

Hi @Martin_Bosano ,

Thanks for putting this on the community.

I noticed that the method getRemoteIssueLinks does not work for Jira DC.

So the solution here is using the Component Accessor.

From Jira DC Source we first need to fetch all the remote links (including web links, confluence links etc).

To do so, please add this snippet on the outgoing.

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

def issueManager = ComponentAccessor.getIssueManager()
def remoteLinkManager = ComponentAccessor.getComponent(RemoteIssueLinkManager)
def realIssue = issueManager.getIssueObject(issue.key)
def remoteLinks = remoteLinkManager.getRemoteIssueLinksForIssue(realIssue)

def linkData = remoteLinks.collect { rl ->
    [
        id          : rl.id,
        url         : rl.url,
        title       : rl.title,
        summary     : rl.summary,
        relationship: rl.relationship,
        globalId    : rl.globalId
    ]
}

replica.customKeys."remoteLinks" = linkData

Now once this is sent over to the other side, you can easily receive them by adding this in the incoming script.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.link.RemoteIssueLink
import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder
import com.atlassian.jira.issue.link.RemoteIssueLinkManager

def issueManager = ComponentAccessor.getIssueManager()
def remoteLinkManager = ComponentAccessor.getComponent(RemoteIssueLinkManager)
def authCtx = ComponentAccessor.getJiraAuthenticationContext()
def user = authCtx.getLoggedInUser()

MutableIssue realIssue = issueManager.getIssueObject(issue.key)

replica.customKeys."remoteLinks"?.each { rl ->

    def existing = remoteLinkManager.getRemoteIssueLinksForIssue(realIssue)
                      .find { it.url == rl.url }

    if (!existing) {
        def link = RemoteIssueLinkBuilder.newInstance()
            .issueId(realIssue.id)
            .url(rl.url)
            .title(rl.title ?: rl.url)
            .relationship(rl.relationship ?: "links to")
            .applicationType("com.atlassian.jira")
            .applicationName("Jira Remote")
            .build()

        remoteLinkManager.createRemoteIssueLink(link, user)  
    }
}

Thanks, Dhiren