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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,987
Community Members
 
Community Events
184
Community Groups

Deleting Comments for Role Level

Question, because I'm stuck... The log shows the <value> I am searching for but the comment does not delete--

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
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.security.roles.ProjectRole
import org.apache.log4j.Logger

def log = Logger.getLogger("com.acme.workflows")

IssueManager issueManager = ComponentAccessor.issueManager
CommentManager commentManager = ComponentAccessor.commentManager

def issueKeys = [<value1>,<value2>]
issueKeys.each
  {issueKey ->
     MutableIssue issue = issueManager.getIssueObject(issueKey)
     List<Comment> comments = commentManager.getComments(issue)
     comments.each
          {comment ->
               log.warn(comment.getRoleLevel())
               if (comment.getRoleLevel() == <value>)
                 {commentManager.delete(comment)
                 }
           }
   }

Anyone know why?

I can manually delete each comment, but there are thousands of tickets.

Any guidance is appreciated.

1 answer

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 04, 2021

Hi @Don Schier 

There can be several reasons for this. But from the first look below if statement seems problematic:

if (comment.getRoleLevel() == <value>)

comment.getRoleLevel returns an instance of ProjectRole class, so you can't do such equality. Instead, you should be checking as below

if (null != comment.getRoleLevel() && <value>.equals(comment.getRoleLevel().getName()))

I also added a null check as it would be null if the comment is public.

I hope I was clear

Cheers

Tuncay

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events