Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Hi @Donald 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
Community showcase
Published in Confluence

Introducing External Collaboration for Confluence

We’re excited to introduce external collaboration for Confluence, now available in early access. It is available to preview for Confluence Cloud Premium and Enterprise customers. (If you're not on ...

205 views 0 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you