# ZD Jira: Customized comment sync + many to one mapping

**URL:** https://community.exalate.com/t/zd-jira-customized-comment-sync-many-to-one-mapping/5285
**Category:** General Questions
**Tags:** usecase, migrated\_question
**Created:** [November 4, 2024, 7:55am UTC](https://community.exalate.com/t/zd-jira-customized-comment-sync-many-to-one-mapping/5285 "2024-11-04T07:55:37Z")
**Posts on this page:** 3
**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:55am UTC](https://community.exalate.com/t/zd-jira-customized-comment-sync-many-to-one-mapping/5285/1 "2024-11-04T07:55:37Z")

</div>

_Originally asked by Syed Majid Hassan on 01 September 2022 [(original question)](https://oldcommunity.exalate.com/questions/58494066)_

* * *

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

* * *

---

<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:55am UTC](https://community.exalate.com/t/zd-jira-customized-comment-sync-many-to-one-mapping/5285/2 "2024-11-04T07:55:39Z")

</div>

_Answer by Syed Majid Hassan on 01 September 2022_

The code which achieves the aforementioned requirements is the following:

**Send ORG info from Zendesk** Expand source

```auto
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)** Expand source

```auto
replica.customFields."Jira Ticket" = issue.customFields."Jira Ticket"

```

**Ensure that all comments received in ZD are treated as Internal** Expand source

```auto
issue.comments = commentHelper.mergeComments(issue, replica, {
		  comment ->
			comment.internal = true
		    comment
		  }
		)

```

**Send only specific comment from Jira** Expand source

```auto
replica.comments = issue.comments.findAll {it.body =~ /\[ZD:\]*/ }

```

**Handle the many to one mapping** Expand source

```auto
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](https://oldcommunity.exalate.com/download/attachments/58494066/ZD%20Jira%20many%20to%20one%20%2B%20comment%20customization.txt?version=1&modificationDate=1662057046755&api=v2)_(old community)_.

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

[ZD Jira many to one + comment customization.mp4](https://oldcommunity.exalate.com/download/attachments/58494066/ZD%20Jira%20many%20to%20one%20%2B%20comment%20customization.mp4?version=1&modificationDate=1662056881454&api=v2)_(old community)_

Thanks  
Majid

* * *

---

<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 6, 2024, 7:56am UTC](https://community.exalate.com/t/zd-jira-customized-comment-sync-many-to-one-mapping/5285/3 "2024-11-06T07:56:21Z")

</div>

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