Unable to Create Sub-Tasks under the Parent Task

Originally asked by Ariel Einfeld on 14 December 2020 (original question)


Hello,
i am using this code from your site and it doesnt work.
it is creating the Sub-Task as a regular Task and not as a sub-task.

OutGoing Sync:

replica.parentId = issue.parentId

Incominfg Sync:

if(firstSync){

issue.projectKey = “RTFACT”

// Set type name from source issue, if not found set a default

issue.typeName = nodeHelper.getIssueType(replica.typeName)?.name ?: “Bug”

}

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](http://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" )

}

}


Answer by Juan Grases on 15 December 2020

Hi!

The problem is that Jira initially create the subtask without parent Id and Exalate tries to sync it like that. You can fix that by adding this on top of your outgoing script:

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


replica.parentId = issue.parentId

That will make sure that Exalate will only sync when the parentId is set by Jira


Answer by Francis Martens (Exalate) on 14 December 2020

What is the problem you encounter?


Comments:

Ariel Einfeld commented on 14 December 2020

when i create a sub-task, it syncs it to the other instance as a Story level issuetype, not as a sub-task under the parent.

Francis Martens (Exalate) commented on 14 December 2020

Can you investigate why it is becoming a story

Looking at

issue.typeName = nodeHelper.getIssueType(replica.typeName)?.name ?: "Bug"

is that the incoming sync is about a story, stories are not sub-tasks.

Can you check it out?

Ariel Einfeld commented on 14 December 2020

That line is just a checker to check if it gets an issueType during the migration, if not it will set it as a Bug.

but that is not the issue here as i have another function right after that where i reset the issue type.

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](http://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" )

}

}

Ariel Einfeld commented on 14 December 2020

and its not working, its creating a story.

Francis Martens (Exalate) commented on 14 December 2020

If the incoming sync is a story, parentId is not set and the section

...issue.typeName = "Sub-task" //Make sure to use the right subtask type here.
....

Is totally ignored.

Can you check the issue type of the incoming sync by throwing an exception

throw new Exception("Incoming issue type = ${replica.typeName}")

Put this on line 1 of your incoming sync on the target side.
Whenever a new message comes in, it will raise an error with the detail you are looking for.
Part of the details is the ‘remote replica’. Have a look into that also - and check if the parentid is set (or not)

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.