I need a script in visual mode to sync all sub-task automatically when the parent issue are synced

Originally asked by Francesco Doricchi on 03 May 2023 (original question)


Hello,

I’m using the visual mode between 2 project of the same instance of Jira on premise data center and I’m trying to sync a “SW Story” issue type that contains some sub-task. I need a script for visual mode to sync in the destination “SW Story” issue all the sub-task from the original issue.

I tried with this:

if(firstSync && replica.parentId){
    issue.typeName     = "Sub-task" //Make sure to use the right subtask type here.
	def localParent = nodeHelper.getLocalIssueFromRemoteId(replica.parentId.toLong())
	if(localParent){
		issue.parentId = localParent.id
	} else {
       throw new com.exalate.api.exception.IssueTrackerException("Subtask cannot be created: parent issue with remote id " + replica.parentId + " was not found. Please make sure the parent issue is synchronized before resolving this error" )
    }
}  
but it didn't work.  
Is there any other script or method to solve my problem?  
Thanks in advance   
BR  
Francesco