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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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) ~[?:?]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Screenshot disappeared after I submitted my comment... Trying again:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Failed again...
Copy as text:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.