1
0
-1


Requirements for ZD-Jira integration:

1. Any comments arriving back from Jira must appear as Internal Notes in Zendesk
2. Only certain comments from Jira should be synced back to ZD i.e. comments starting with [ZD:]
3. The organization and Zendesk ticket number should be reflected in the Environment field in Jira.


Multiple to one sync requirements:

1. Multiple Zendesk tickets to be linked to same Jira issue. 
2. The Environment field in Jira should have information of all the linked tickets. 
3. Any updates from Jira should follow the general rules stated above. 

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      The code which achieves the aforementioned requirements is the following:


      Send ORG info from Zendesk
      def orgId = issue.organization_id
      if(orgId){
        def orgName = httpClient.get("/api/v2/organizations/"+(long)orgId+".json").organization.name
        replica.customKeys."Organization" = orgName
      }
      Send Jira ticket num from ZD (for many to one)
      replica.customFields."Jira Ticket" = issue.customFields."Jira Ticket"
      Ensure that all comments received in ZD are treated as Internal
      issue.comments = commentHelper.mergeComments(issue, replica, {
      		  comment ->
      			comment.internal = true
      		    comment
      		  }
      		)
      Send only specific comment from Jira
      replica.comments       = issue.comments.findAll {it.body =~ /\[ZD:\]*/ }
      Handle the many to one mapping
      if(firstSync){
         issue.projectKey   = "CM" 
         issue.typeName     = nodeHelper.getIssueType(replica.type?.name, issue.projectKey)?.name ?: "Task"
            
         def remoteIssueUrn = replica.customFields."Jira Ticket"?.value
         if(remoteIssueUrn){
              def localIssue = httpClient.get("/rest/api/2/issue/"+remoteIssueUrn)
              if(localIssue == null) 
                  throw new com.exalate.api.exception.IssueTrackerException("Issue with key "+remoteIssueUrn+" was not found")
              //debug.error(localIssue)
              issue.id = localIssue?.id
              issue.key = localIssue?.key
              def newData = httpClient.get("/rest/api/latest/issue/"+issue.key)
      
              //debug.error("${newData.fields.customfield_10092}")
              issue.customFields."Environment".value = newData.fields.customfield_10092 + "\nOrg:" + replica.customKeys."Organization" + "\t\tTicket num from ZD: " + replica.key 
              return;
          }
          issue.summary      = replica.summary
          issue.description  = replica.description
          issue.customFields."Environment".value = "Org:" + replica.customKeys."Organization" + "\t\tTicket num from ZD: " + replica.key 
      }


      The entire code is attached here


      A demonstration of how this works can be found in the attached video:

      ZD Jira many to one + comment customization.mp4


      Thanks
      Majid


        CommentAdd your comment...