Jira <-> Zendesk - Visual version - Only send public replies from Jira

Originally asked by Svein Tvedt on 27 July 2021 (original question)


Hi again :smile:

I am not able to figure this one out and I hope you can help me out.

I am trying to update my Visual connection between Zendesk and Jira and the script that I created below based on the answer that you gave me in the last post I submitted.

What I am trying to accomplish now is that I only want public reply comments from Jira to be synchronized with Zendesk. Jira (Payments) to Zendesk (CS).

I have tried looking up the documentation, but it seemed to be geared towards Scripting connections as I am not getting that code to work. I tried what was posted here, but thatโ€™s not working for me: Only sync internal comments (old community) (doing it like this: replica.comments = issue.comments.``findAll``{!it.internal} which can be found here https://docs.idalko.com/exalate/display/ED/How+to+synchronize+comments)

if (executionInstanceName == "Payments") {
    replica.comments = nodeHelper.getHtmlComments(issue)
    replica.comments = commentHelper.mergeComments(issue, replica,{
       comment ->
       comment.body =
          comment.author.displayName +
                  " commented: \n" +
          comment.body + "\n"
    }
)
}
if (executionInstanceName == "CS") {
    replica.comments = commentHelper.mergeComments(issue, replica, {
    comment ->
    comment.internal = true
    comment.body =
        comment.author.displayName +
                " commented: \n" +
        comment.body + "\n"
  }
)
}

Would you be able to take a look at this and help me out?

Thanks in advance!


Comments:

Ariel Aguilar commented on 28 July 2021

Hi Svein,

For this case, this should work:

if (executionInstanceName == "JIRACLOUD") {
    def includeComments = commentHelper.mergeComments(issue, replica).collect{it}
    issue.comments     = nodeHelper.toMarkDownComments(includeComments)
}
if (executionInstanceName == "ZD") {
    replica.comments = replica.comments.findAll{!it.internal}
    issue.comments = commentHelper.mergeComments(issue, replica, {
    comment ->
    comment.internal = true
    comment.body =
        comment.author.displayName +
                " commented: \n" +
        comment.body + "\n"
  }
)
}

Let me know how it goes!

Kind regards,

Ariel

Chris Lord commented on 29 July 2021

Hi Ariel Aguilar ,

Please note that I am following up as Svein is on leave.

I have implemented the following code.

if (executionInstanceName == "Payments") {
    def includeComments = commentHelper.mergeComments(issue, replica).collect{it}
    issue.comments     = nodeHelper.toMarkDownComments(includeComments)
}
if (executionInstanceName == "CS") {
    replica.comments = replica.comments.findAll{!it.internal}
    issue.comments = commentHelper.mergeComments(issue, replica, {
    comment ->
    comment.internal = true
    comment.body =
        comment.author.displayName +
                " commented: \n" +
        comment.body + "\n"
  }
)
}

However I am still receiving an internal comment on Zendesk when an internal comment is left by an agent on Jira.

For clarity, Payments is Jira and Zendesk is CS.

Please let me know if you see anything wrong.

Thanks,

Ariel Aguilar commented on 29 July 2021

Hi there,

If you try this:

if (executionInstanceName == "Payments") {
    def includeComments = commentHelper.mergeComments(issue, replica).collect{it}
    issue.comments     = nodeHelper.toMarkDownComments(includeComments)
    issue.comments = issue.comments.findAll{!it.internal}
}
if (executionInstanceName == "CS") {
    issue.comments = commentHelper.mergeComments(issue, replica, {
    	comment ->
    	comment.internal = true
    	comment.body =
        comment.author.displayName +
                " commented: \n" +
        comment.body + "\n"
  }
)
}

Let me know if only public comments are sent now.

Kind regards,

Ariel

Chris Lord commented on 30 July 2021

Hi Ariel,

Thanks for the help.

I have implemented the recent script, clicked on the save button and published changes.

I then made a public and internal comment on Jira as per the screenshot below.

When checking Zendesk it still receiving the internal comment from Jira and sending it as an internal comment on Zendesk.

Can you see anything wrong with here or have any suggestions on the scripting I can try out next.

Appreciate your help on this.

Thanks

Svein Tvedt commented on 03 August 2021

Hi Ariel Aguilar

Just bumping the thread, thanks

Answer by Ariel Aguilar on 04 August 2021

Hi Svein,

Sorry if I took some time, it seems we were conflicting with one of the limitations when using Visual Connections and actually if you are going to have this kind of configurations it is recommended to go to Script based connection, however I found a workaround for the original topic:

if (executionInstanceName == "Payments") {
    def includeComments = commentHelper.mergeComments(issue, replica).collect{it}
    issue.comments     = nodeHelper.toMarkDownComments(includeComments)
}

if (executionInstanceName == "CS") {
    replica.getClass().fields
    def locked = replica.getClass().declaredFields.find{it.name == "_locked"}
    locked.setAccessible(true)
    locked.set(replica, false)
    replica.addedComments = replica.addedComments.findAll{!it.internal}
    issue.comments = commentHelper.mergeComments(issue, replica, {
    comment ->
    comment.internal = true
    comment.body =
        comment.author.displayName +
                " commented: \n" +
        comment.body + "\n"
  }
)
}

Let me know if this works now.

Kind regards,

Ariel


Comments:

Svein Tvedt commented on 05 August 2021

Hi Ariel Aguilar

This worked perfectly, thanks so much, we will check out script based connections in the future (old community)

BR,
Svein Tvedt

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