JIRA SERVER

This article describes how to sync issue links details to a custom field using  JIRA Issue Link API.

Source side

Send over the issue link details

Outgoing sync


import com.atlassian.jira.component.ComponentAccessor
// ...
// other parts of the script are not shown for simplicity
def jIssue = ComponentAccessor
  .getIssueManager()
  .getIssueObject(issue.key)
def ilm = ComponentAccessor.getIssueLinkManager()
def linkToMapFn = { ldir -> 
  { l -> 
    [
      "from": [
        "id": l.sourceObject.id,
        "key": l.sourceObject.key
      ],
      "to": [
        "id": l.destinationObject.id,
        "key": l.destinationObject.key
      ],
      "direction": ldir,
      "linkType": (ldr == "outward")? l.issueLinkType.outward : l.issueLinkType.inward,
      "style": l.issueLinkType.style
    ] 
  } 
}
replica.customKeys.issueLinks = [
"out": ilm
  . getOutwardLinks(jIssue.id)
  .collect(linkToMapFn("outward"))
"in": ilm
  . getInwardLinks(jIssue.id)
  .collect(linkToMapFn("inward"))
]


Destination Instance

Add the script below in the Incoming sync of the Destination instance to receive issue links information from the Source Instance.


// add the links information to the custom field
issue.customFields."Custom field name".value = replica.issueLinks.toString()

See Also