How to Sync Sub-tasks between Jira On-Premise and Jira Cloud

    This article shows examples of how to sync sub-tasks between Jira On-Premise and Jira Cloud.

    Warning: Despite our best efforts, code can change without notice due to a variety of factors. If you encounter an issue in any of the code shown here and find that a specific block of code is not correct, or is causing errors, please check with the Community to find an updated version.

    Syncing Sub-tasks between Jira On-Premise and Jira Cloud

    To exchange sub-tasks between Jira-On-Premise and Jira Cloud, you need to specify the mapping for sending the parent id from one side and receive that parent id on target side to find its corresponding id .

    Jira On-Premise

    Outgoing sync

    replica.parentId = issue.parentId

    Incoming sync

    if(firstSync){
       issue.projectKey   = "ABC" 
       // Set type name from source issue, if not found set a default
       issue.typeName     = nodeHelper.getIssueType(replica.type?.name, issue.projectKey)?.name ?: "Task"
       if(firstSync && replica.parentId){
          issue.parentId = null
          if (replica.parentId){
             //localParent = syncHelper.getLocalIssueKeyFromRemoteId(replica.parentId)
             localParent = nodeHelper.getLocalIssueKeyFromRemoteId(replica.parentId,"issue")
             //debug.error("localParent"+localParent)
             if (localParent){
                issue.parentId = localParent.id
                issue.typeName     = "Sub-task"
                }
             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" )
             }
          }
       }
    }
    issue.summary      = replica.summary
    .....

    Jira Cloud

    Outgoing sync

    if(issue.typeName == "Sub-task" && issue.parentId == null) return
    replica.key  = issue.key
    replica.type = issue.type
    .....
    replica.parentId  = issue.parentId
    ......

    Note: The first line needs to be added because Jira Cloud initially creates the subtask without a parent Id. The lack of a parentId would result in failure on other side .

    Incoming sync

    if (firstSync) {
      issue.projectKey  = "XYZ"
      def issueType = replica.type?.name.toString()
      issue.typeName    = nodeHelper.getIssueType(replica.type?.name, issue.projectKey)?.name ?: "Task"
      if(firstSync && replica.parentId) {
        issue.parentId = null
        if (replica.parentId) {
          localParent = syncHelper.getLocalIssueKeyFromRemoteId(replica.parentId)
          if (localParent) {
    	      issue.parentId = localParent.id
            issue.typeName     = "Sub-task" //Make sure to use the right subtask type here.
          }
        }
      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" )
        }
      }
    } 
     
    issue.summary      = replica.summary
    .....



    Note: Both the parent task and the sub-task must be in sync for the parent link to be created in the child issue.