1
0
-1

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.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
    }
}


But it doesn't work..

Thanks in advance

Giancarlo

  1. Giancarlo Andreoni

    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.


  2. Ariel Aguilar

    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/

    Kind regards,

    Ariel

  3. Giancarlo Andreoni

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

    ...

CommentAdd your comment...