How to create a normal issuelink (Local synchronisation)

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.

How?Source: Jira Server/Datacenter (old community)


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
if (firstSync) {
    if(replica.project.key == "HAS"){
       issue.projectKey   = "AN"
       issue.typeName     = nodeHelper.getIssueType(replica.type?.name, issue.projectKey)?.name ?: "Task"
    
    }
    if(replica.project.key == "AN"){
       issue.projectKey   = "HAS"
       issue.typeName     = nodeHelper.getIssueType(replica.type?.name, issue.projectKey)?.name ?: "Task"

    }
    syncHelper.syncBackAfterProcessing()
}
  • 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)
      
}

Give it a try


This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.