Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I delete a specific comment from an issue based on the comment id with Scriptrunner?

Markus W_ BENES
Contributor
July 21, 2023

How can I delete a specific comment from an issue based on the comment id with Scriptrunner? Example: Delete from Issue 10 Comment 223

2 answers

1 accepted

0 votes
Answer accepted
Mohamed Benziane
Community Champion
July 22, 2023
Markus W_ BENES
Contributor
July 30, 2023

Thank you for your tip :)

0 votes
Markus W_ BENES
Contributor
July 31, 2023

here is the code that is actually working for me; could be better but does the job:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager

String issueKey = "AB-1234"
Integer commentID = 1234567

IssueManager issueManager = ComponentAccessor.issueManager
CommentManager commentManager = ComponentAccessor.commentManager
MutableIssue issue = issueManager.getIssueObject(issueKey)

List<Comment> comments = commentManager.getComments(issue)
comments.each {comment ->
    if (comment.id == commentID) {
        commentManager.delete(comment)
    }
}

Suggest an answer

Log in or Sign up to answer