Post only 1 comment after ticket is resolved/closed

Originally asked by Adriano Mazi on 29 December 2020 (original question)


I have a connection between my Jira Server and Jira Service Desk and I was able to create a configuration that will post a comment in the ticket on SD after my ticket on Jira is resolved or closed.

My current problem is that my configuration will post a new comment after every new change of status. Is there any way to prevent and post only 1 comment, regardless if the ticket is resolved and later closed, for example.


Answer by Francis Martens (Exalate) on 08 January 2021

One approach you can take to solve this one is to consult the previous replica.
The previous replica contains the content of the message preceding the current message.

For instance - I assume that whenever an issue is resolved, the resolution is set on the remote issue.
Following code will add the comment only once

// Previous is only available if there was a previous sync, so firstSync is false
if (!firstSync && previous.resolution == null && replica.resolution != null) {
   // add comment that the issue has been resolved 
}

You could also add a comment when the issue gets reopened

if (!firstSync && previous.resolution != null && replica.resolution == null) {
   // add comment that the issue has been reopened 
}

Another example can be found on the documentation site
How to convert remote status changes to local comments


Answer by Adriano Mazi on 11 January 2021

Hi Francis, this help me to achieve what I need. I also added the remote status changes but with a small change, in order to not provide status when the ticket is resolved/closed. The comment for these statuses will come from your code:

// Add a comment when the remote issue has been updated
if (!replica.status.equals(previous?.status) && replica.resolution == null) {
String message = "${replica.key}: Status updated from '${previous?.status?.name}' to '${replica?.status?.name}'"
issue.comments = commentHelper.addComment(issue.comments){ comment ->
comment.body = message
comment.restrictSync = true
comment.internal = false
}
}

// Add a comment when the remote issue has been resolved
if (!firstSync && previous.resolution == null && replica.resolution != null) {
String syncissue_done = "Development for Ticket '${replica.key}' has been completed"
issue.comments = commentHelper.addComment(issue.comments){ comment ->
comment.body = syncissue_done
comment.restrictSync = true
comment.internal = false
}
}

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