Visual connection - epic, story and subtask

script_segment.groovy
if (executionInstanceName == "b") {

    if (b.issue.type.name == "Epic") {
        b.issue.customFields."Epic Name"?.value = a.issue.customFields."Epic Name"?.value
    } else {
        
        if (a.issue."parentId")  {
            // this is a subtask - set the local parent it

            Long remoteParentId = a.issue.parentId as Long
            Long localParentId = nodeHelper.getLocalIssueKeyFromRemoteId(remoteParentId, "issue").id
            b.issue.parentId = localParentId

        } else {
            // set the epic link custom field, such that it points to the twin epic of the parent of the source
            
            def remoteEpicIssueKey = a.issue.customFields."Epic Link"?.value?.urn
            b.issue.customFields."Epic Link".value = nodeHelper.getLocalIssueKeyFromRemoteUrn(remoteEpicIssueKey, "issue")
        }
    }
}