Issues with the Subtask Sync

Hi team,

Trying to sync the subtask from Jira on Prem to Jira Cloud. The subtask do gets synced if exalated manually or via the trigger and here is the script:

JoP outgoing:

replica.parentId = issue.parentId

JC Incoming:

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" )
}

}

However, if try the following snippet in order sync the subtasks automatically, the subtasks do not get synced:

Added the following in the JoP outgoing:

// Automatically sync all subtasks when syncing parent task httpClient.get("/rest/api/3/issue/"+issueKey.id).fields.subtasks?.collect{ def subTaskKey = new com.exalate.basic.domain.BasicIssueKey(it.id, it.key) syncHelper.exalate(subTaskKey) }

All the snippets are being taken from this article:

Note that the same snippets are added when checked for Jira On Prem: How to Sync Tasks and Subtasks in Jira On-premise

Please check and advise on how to address this - Thank you!

Great question! You’re on the right track with syncing subtasks between Jira On-Prem and Jira Cloud, and you’ve referenced the correct documentation. Let’s break down what’s happening and how to get the automatic subtask sync working smoothly.

What’s working:

  • Manual or trigger-based subtask sync works fine.
  • Your outgoing and incoming sync scripts for parent/child relationships are set up as per the docs.

What’s not working:

  • When you try to automatically sync all subtasks by adding the syncHelper.exalate(subTaskKey) logic in the outgoing script, the subtasks don’t sync as expected.

Why this happens:
The main reason is that the syncHelper.exalate() function only works if the Exalate app has access to the subtasks you’re trying to sync. In Jira On-Prem, the REST API endpoint you’re using (/rest/api/3/issue/) is for Jira Cloud, not Jira Server/Data Center. For Jira On-Prem, you should use the appropriate REST API endpoint and field structure.

How to fix it:

  1. Use the correct REST API endpoint for Jira On-Prem:
    For Jira Server/Data Center, the endpoint should be /rest/api/2/issue/ instead of /rest/api/3/issue/.

  2. Adjust the script for Jira On-Prem:
    Here’s how you can modify your outgoing sync script for Jira On-Prem:

    // Automatically sync all subtasks when syncing parent task
    def response = httpClient.get("/rest/api/2/issue/${issueKey.id}")
    def subtasks = response.fields?.subtasks
    subtasks?.each {
        def subTaskKey = new com.exalate.basic.domain.BasicIssueKey(it.id, it.key)
        syncHelper.exalate(subTaskKey)
    }
    

    This script fetches the subtasks for the parent issue and triggers Exalate for each subtask.

  3. Make sure permissions are correct:
    The Exalate app user must have permission to view the parent issue and its subtasks.

  4. Parent must be synced first:
    Subtasks can only be created if their parent exists on the destination. Your incoming script already checks for this, which is perfect.

References:

Summary:
Update your outgoing script to use the correct API endpoint for Jira On-Prem, and ensure the Exalate user has the right permissions. This should get your automatic subtask sync working as expected.

Hope this clears things up and gets your sync running smoothly!

Hi @Sonal_Otwani

Can we check this further? Thank you!