Delete all comments of an issue.

This article provides the code snippet to delete all comments of the current issue using post-function, callJira Nunjucks filter, and this Jira Cloud REST API.

 Instructions

  1. Navigate to the intended workflow and open it in Edit mode.

  2. Select the required transition.

  3. Select the Post functions tab and click Add post function.

  4. Add the post-function.

  5. Add the below code in “Nunjucks script”:

    {% set allComments = issue.fields.comment.comments | field("id") %} {% for comm in allComments %} {{ "/rest/api/2/issue/:issueKey/comment/:id" | callJira( params={issueKey:issue.key,id:comm}, verb="delete" )}} {% endfor %}
  6. Add the post-function and publish the workflow.

With this, all the comments on the current issue are deleted when the transition is executed.

Note that once comments are deleted, they cannot be restored. So please implement this script with caution.

References