Originally asked by Francis Martens (Exalate) on 01 April 2020 (original question)
I have a local connection between two Jira Software projects.
Whenever an issue is exalated, I would like to have a normal issue link between the twins.
Answer by Francis Martens (Exalate) on 01 April 2020
The method to create such a link is
Ensure that the outgoing message contains the id of the issue under sync
replica.customKeys.issueId = issue.id
Ensure that during the first sync, the syncBackAfterProcessing is called
This is necessary because at during the firstSync the issue is not yet created, and the issue.id is required to build a link
Whenever getting an incoming message, ensure that a link is created if not yet existing
if (!firstSync) {
/*********************************** ISSUE LINK *******************
* Make sure there is an issue link to the other side
********************/
def nserv = com.atlassian.jira.component.ComponentAccessor.getOSGiComponentInstanceOfType(com.exalate.api.node.INodeService.class)
def proxyUser = nserv?.getProxyUser()
def ilm = com.atlassian.jira.component.ComponentAccessor.getIssueLinkManager()
def RELATES = 10003L // 10003 is the 'relates' issue link type
Long localId = Long.parseLong(issue.id)
Long remoteId = Long.parseLong(replica.customKeys.issueId)
// check if the link exists
def linkExists = ilm.getInwardLinks(RELATES).find { it.sourceId == remoteId } ||
ilm.getOutwardLinks(RELATES).find { it.destinationId == remoteId }
if (!linkExists)
ilm.createIssueLink(localId, remoteId, RELATES, null, proxyUser)
}