Sync Custom Field in JIRA to Public Reply Comments in Zendesk

Originally asked by Spencer Johnson on 08 July 2020 (original question)


I want to sync a custom field in jira to public reply in zendesk, ie. any time custom field is editing a new public reply is created in zendesk. Note: I still want all other comments in JIRA to be added as internal notes in zendesk. The custom field in JIRA is called “External Notification”

Here is what I have so far and it is working to add internal comments in Zendesk but not public replies.

Zendesk Incoming Sync:

issue.comments = commentHelper.mergeComments(issue, replica, {it.internal = true; it})
if(replica.customFields."Test Field"?.value) { 
	issue.comments = commentHelper.addComment(replica.customFields."Test Field".value, true, issue.comments) 
}

JIRA Outgoing Sync:

replica.comments = issue.comments
replica.customFields."Test Field" = issue.customFields."External Notification" 

Answer by Juan Grases on 09 July 2020

Hi!

That code should be adding a comment for every sync zendesk received where the CF Test Field value is set (not only the update that set it). So probably that’s not what you want. Still is possible to solve your use case with:

def testFieldV = replica.customFields."Test Field"?.value
if(testFieldV){   
if(firstSync || testFieldV != previous.customFields."Test Field"?.value)      
issue.comments = commentHelper.addComment(issue.comments){comment ->
   comment.internal = false
   comment.body = testFieldV
  }
}

Comments:

Spencer Johnson commented on 13 July 2020

Juan Grases Thanks for the info! I tried what you suggested and its not adding a comment so I modified it to

def testFieldV = replica.customFields."Test Field"?.value
if(testFieldV) {   
    if(firstSync || testFieldV != previous.customFields."Test Field"?.value)  {    
        commentHelper.addComment(issue.comments){comment ->
                                                comment.internal = false
                                                comment.body = testFieldV
        }
        issue.customFields."Test Field".value = replica.customFields."Test Field".value
    }
}

ie added a line to sync to the value to a custom field in Zendesk to see if both of the if statements are working (which they are since the value is synced to that custom field in zendesk. So it looks like the below line is the issue:

commentHelper.addComment(issue.comments){comment ->
                                                comment.internal = false
                                                comment.body = testFieldV
        }

And does not successfully add a comment to the ticket in Zendesk, Any ideas on how to fix that?

Juan Grases commented on 13 July 2020

Hi! My bad, the code should be:

issue.comments = commentHelper.addComment(issue.comments){comment ->
                                                comment.internal = false
                                                comment.body = testFieldV
        }

I am editing my initial answer

Spencer Johnson commented on 14 July 2020

Juan Grases that worked!!! Thank you so much!

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