Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Delete all comments of all issues that fulfil a certain JQL

Gisela Lassahn June 9, 2023

I'm searching for a way to delete all comments of all issues which fulfil a certain JQL statement.

We're using Jira DC 8.20.3 and do not have Script Runner or something similar.

My idea was to do it with Jira automation, by calling the REST API using the action "Send web request".

But as I am a totally beginner regarding Jira automation, Jira REST API and REST API in common, I've got no idea how to begin.

Can anybody help me?

3 answers

Suggest an answer

Log in or Sign up to answer
1 vote
Reece Lander _ScriptRunner - The Adaptavist Group_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 9, 2023

I know you mentioned that you do not have ScriptRunner. But I'll take a moment to show off some new features of ScriptRunner that would make this kind of automation very simple.

ScriptRunner 7.11.0+ contains our new HAPI scripting syntax. This is still scripting, so more complex than native Jira automation, but with drastically simpler syntax, more approachable by non programmers.

For example, here is a HAPI script that deletes all comments from all issues matching a JQL query:

 

Issues.search('project = SR').each { issue ->
issue.comments.each { comment ->
comment.delete()
}
}

You can use HAPI anywhere in ScriptRunner that scripting is available, for example you could run this directly in the Script Console, or as part of a scheduled job or event listener.

A lesser known feature of ScriptRunner is that we offer an automation action, this means you can configure a trigger in Jira automation, then run a ScriptRunner script (and HAPI) as an action. This integration will show up if you have both apps installed and licensed.

Hopefully you can see that ScriptRunner is now a tool for everybody, not just scripting experts.

Cheers!

Reece

David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 1, 2024
David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 1, 2024

2024-02-01T11:36:04,869 ERROR [common.UserScriptEndpoint]: ************************************************************************************* 2024-02-01T11:36:04,869 ERROR [common.UserScriptEndpoint]: Script console script failed: java.lang.UnsupportedOperationException: Cannot set or mutate an ImmutableGenericValue at com.atlassian.jira.util.ofbiz.ImmutableGenericValue.set(ImmutableGenericValue.java:63) ~[classes/:?] at org.ofbiz.core.entity.GenericEntity.set(GenericEntity.java:283) ~[entityengine-3.0.9.jar:?] at com.atlassian.jira.issue.util.DefaultIssueUpdater.doUpdate(DefaultIssueUpdater.java:79) ~[classes/:?] at com.atlassian.jira.issue.util.DefaultIssueUpdater.doUpdate(DefaultIssueUpdater.java:63) ~[classes/:?] at com.atlassian.jira.issue.comments.DefaultCommentManager.doDelete(DefaultCommentManager.java:483) ~[classes/:?] at com.atlassian.jira.issue.comments.DefaultCommentManager.delete(DefaultCommentManager.java:418) ~[classes/:?] at com.atlassian.jira.issue.comments.CommentManager$delete$5.call(Unknown Source) ~[?:?] at _CSLT.DeleteAUsersComments$_run_closure1$_closure2.doCall(DeleteAUsersComments.groovy:32) ~[?:?] at _CSLT.DeleteAUsersComments$_run_closure1.doCall(DeleteAUsersComments.groovy:29) ~[?:?] at _CSLT.DeleteAUsersComments.run(DeleteAUsersComments.groovy:28) ~[?:?]

0 votes
Gisela Lassahn June 13, 2023

Today I noticed that there is no sense in deleting the comments because users can still see them in the history of the issue.
We wanted to anonymize issues when they are closed for a long time, but not archive or delete them, because of statistical reasons.
So we have to manipulate the database directly anyway.

0 votes
Metin Savignano June 9, 2023

You did not explicitly mention if this is something that has to be done on a regular basis and/or in an automated way.

Just to make sure that you are aware of this option:

If you have to do this once or only occasionally, you can just run the query and then bulk edit the results. The option for this can be found behind the three dots (...) on the top right.

Otherwise, I did not test it, but I would assume that this could be an approach:

Metin Savignano June 9, 2023

Screenshot disappeared after I submitted my comment... Trying again:

Metin Savignano June 9, 2023

Failed again...

 

Copy as text:

  1. When: Scheduled at (some time)
  2. Then: Lookup isses
    Search for issues using JQL
  3. And: Remove comment from issue
    {{#issue.comments}}
Gisela Lassahn June 11, 2023

Screenshot 2023-06-12 081846.jpg

This is the result of trying it via automation. It seems that it only works with a certain comment id. In Jira DC 8.20.3 there is no action "Lookup issues" and "Remove comment from issue".

I also know bulk edits, but though the option "Edit issues" with detail "Change comment" makes people think they can change existing comments, it will only add a new comment to the selected issues. So this also won't help me.

Metin Savignano June 11, 2023

Looks like it needs a closing / as in 

{{#issue.comments}} {{/}}

See https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/ for more details and explanations 

Gisela Lassahn June 11, 2023

If I do it like you've suggested, I can save the rule, but executing the rule results in an error message:

"Error deleting comment - smart-value did not resolve into a number."

Probably the action "Delete comment" has been designed for single comments only rather than to delete all comments of an issue.

TAGS
AUG Leaders

Atlassian Community Events