# Subtasks synch

**URL:** <https://community.exalate.com/t/subtasks-synch/4984>\
**Category:** General Questions\
**Tags:** onpremise-jira, migrated\_question\
**Created:** [November 4, 2024, 7:36am UTC](https://community.exalate.com/t/subtasks-synch/4984 "2024-11-04T07:36:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 7:36am UTC](https://community.exalate.com/t/subtasks-synch/4984/1 "2024-11-04T07:36:20Z")

</div>

_Originally asked by Giancarlo Andreoni on 17 December 2021 [(original question)](https://oldcommunity.exalate.com/questions/42829841)_

* * *

In my Jira on-prem instance I should have to synch issues in such a way:

- Scenario 1:

TK.Defect.1(customfield “A” = “1”) \> MW.Defect.1

TK.Defect.1(customfield “A” = “1”).Subtask(type=“Sub-Porting”) \> MW.Defect.1.Subtask(type=“Sub-Porting”)

- Scenario 2:

TK.Defect.2(customfield “A” = “2”) \> NO SYNCH

TK.Defect.2(customfield “A” = “2”).Subtask(type=“Sub-Defect”) \> MW.Defect.2

TK.Defect.2(customfield “A” = “2”).Subtask(type=“Sub-Porting”) \> MW.Defect.2.Subtask(type=“Sub-Porting”)

I managed correctly the first senario but I have a problem in the second one, how can I find the id of the subtask with “Sub-Defect” type when generating the MW.Defect.Subtask(type=“Sub-Porting”), in order to associate it as a subtask to the MW.Defect.2?

I tryied something like this in the Incoming sync:

if(replica.parentId){  
// look up the twin parent  
def localParent  
if (replica.customFields.“A”.value == “2”){  
replica.fields.subtasks?.collect{  
if(it.getIssueType() == “Sub-Defect”){  
localParent = nodeHelper.getLocalIssueFromRemoteId([it.id](http://it.id).toLong())  
}  
}  
}else{  
localParent = nodeHelper.getLocalIssueFromRemoteId(replica.parentId.toLong())  
}  
// if found, then set it, else don’t create the subtask  
if(localParent){  
issue.parentId = [localParent.id](http://localParent.id)  
}  
}

But it doesn’t work..

Thanks in advance

Giancarlo

* * *

#### Comments:

> **Giancarlo Andreoni commented on 17 January 2022**
>
> > To be more clear, here below a schema of issues and sub tasks that I have to sync between two projects (TK and MW) of the same Jira on-prem instance.
> 
> When the value of custom field “A” of “Defect” issues in project TK is “2”, a sub-task is automatically generated, in this case, I should create a synchronized issue on project MW and this one should be the parent for the other sub-tasks.
> 
> ![](https://dub1.discourse-cdn.com/flex018/download/attachments/42829841/image2022-1-17_10-17-11.png?version=1&modificationDate=1642411031677&api=v2)

> **Ariel Aguilar commented on 28 March 2022**
>
> > Hi Giancarlo,
> 
> We can see you have an interesting use case, have you considered to get extra help by contacting any Exalate partner? [https://exalate.com/partners/](https://exalate.com/partners/)
> 
> Kind regards,
> 
> Ariel

> **Giancarlo Andreoni commented on 28 March 2022**
>
> > Thank you for the suggestion Ariel but I solved the problem, here below details if someone need it:
> 
> \>\> incoming sync:
> 
> …
> 
> def issueManager = com.atlassian.jira.component.ComponentAccessor.issueManager  
> def customFieldManager = com.atlassian.jira.component.ComponentAccessor.customFieldManager  
> def parentIssue = issueManager.getIssueObject(replica.parentId as Long)  
> def masterIssueKey = parentIssue.key  
> def cField = customFieldManager.getCustomFieldObjectByName(“A”)  
> def cFieldValue = ((String)parentIssue.getCustomFieldValue(cField)).trim()
> 
> if(cFieldValue == “2”){  
> def subtaskManager = com.atlassian.jira.component.ComponentAccessor.getSubTaskManager()  
> def subTasks = parentIssue.getSubTaskObjects()
> 
> ```
> if(!subTasks.empty) {
> 
> //searching into the sub\-task for my issuetype only  
> subTasks.each { it \-\>  
> if(it.getIssueType().name \=\= "Sub\-task"){  
> //do nothing  
> } else if(it.getIssueType().name \=\= "Sub\-Defect"){  
> //Found my issuetype  
> masterIssueKey \= it.key  
> } else {  
> //do nothing  
> }  
> }  
> }  
> localParent \= nodeHelper.getLocalIssueFromRemoteUrn(masterIssueKey)  
> if(localParent){  
> issue.parentId \= [localParent.id](http://localParent.id)  
> issue.summary \= localParent.key \+ " \- " \+ replicaSummary.substring(11, replicaSummary.length())  
> } else {  
> //issue.summary \= replicaSummary.substring(11, replicaSummary.length())     
> throw new com.exalate.api.exception.IssueTrackerException("COMPLEX \- 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")  
> } 
> 
> ```
> 
> …

---

<div class="post-metadata">

**Author:** ![Majid](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/majid/32/343_2.png) [@Majid](https://community.exalate.com/u/Majid)\
**Post date:** [December 4, 2024, 9:19am UTC](https://community.exalate.com/t/subtasks-synch/4984/2 "2024-12-04T09:19:07Z")

</div>

Closed on December 4, 2024, 9:19am UTC


