First you want to sync over the Epic from one Jira Cloud to another.
Outgoing sync
Epic.send()
Incoming Sync
Epic.receive()
If you want to make sure epics and their child issues are in sync you can create a trigger that syncs newly create epic links automatically
You can do something like this. You can create 2 triggers like the example or just one that checks on the project itself.
Example
// This will only sync over epics
project = "Project name" AND issuetype = "Epic"
// This wil send over all epic link issues
project = "Project name" AND issuetype != "Epic" AND "Epic Link" is not EMPTY
When you remove the epic link on one side you want it to be removed on the other side as well, you can do this with the following code.
Incoming sync
if (!firstSync && (replica.customKeys."Epic Link" == null && issue."Epic Link" !=
null)){
// removes epic link when replica.customKeys."Epic Link" is null and the local
issue still has it's epic link
// You can find the "Epic link" field within the Entity sync status.
issue."Epic Link" = null
}