Hello,
I created a bulk update to add a comment to all issues in "To Do" status in my project. The comment triggered a process that copied the value from the Story Points field to the Original Story Points field, though I'm not sure exactly how it worked. The comment was added to 315 issues. Here's the comment I added:
Copying points to "original story points"
Now, I'd like to delete this comment from all the issues. I've searched online and in the forum but couldn't find a solution that I understood. I have access to ScriptRunner but am unfamiliar with how to use it.
It's not critical if I can't delete the comments, but I'd prefer to. :)
Any advice would be appreciated!
All the best,
-CLK
Hi @Coady Krzysztof welcome to the community.
That's an interesting scenario, perhaps I'm not so familiar with the scriptrunner for jira cloud, I try create an solution in datacenter version and translate to the cloud version.
Probably you gonna need make some tests and adapt some parts, but I'll explain the logical here.
We gonna use an combination of JQL and Jira Rest API.
With the JQL we gonna define the issues we want check for the comments, for every issue in the jql response, we gonna look for the comments and check if the contains the text we want delete, in that case Copying points to "original story points".
If the comment contains the text, we delete, if not we go to the next until the script finish the jql result.
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
def commentTextToDelete = "Copying points to \"original story points\""
def baseUrl = "https://your-domain.atlassian.net"
def searchUrl = "${baseUrl}/rest/api/3/search"
def deleteCommentUrl = { issueKey, commentId -> "${baseUrl}/rest/api/3/issue/${issueKey}/comment/${commentId}" }
// Search for issues using JQL
def projectKey = "YOUR_PROJECT_KEY"
def jql = "project = ${projectKey} AND status = 'To Do'"
def searchResponse = get(searchUrl)
.queryString("jql", jql)
.queryString("fields", "comment")
.queryString("maxResults", "100")
.asObject(Map)
// Check if JQL returned issues
if (!searchResponse.body.issues) {
log.warn("No issues found matching JQL: ${jql}")
return
}
// Process each issue
searchResponse.body.issues.each { issue ->
def issueKey = issue.key
def comments = issue.fields.comment?.comments ?: []
comments.each { comment ->
if (comment.body.contains(commentTextToDelete)) {
log.info("Deleting comment from issue ${issueKey}")
def deleteResponse = delete(deleteCommentUrl(issueKey, comment.id)).asString()
if (deleteResponse.status == 204) {
log.info("Successfully deleted comment from issue ${issueKey}")
} else {
log.error("Failed to delete comment from issue ${issueKey}: ${deleteResponse.status}")
}
}
}
}
log.info("Finished processing issues.")
Please have a try and let me know if this helps you.
Best regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.