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,455,378
Community Members
 
Community Events
175
Community Groups

Scriptrunner listener last changed comment

Edited

Hi everyone!

I am looking for a possibility to get the latest changed comment within an issue. I know that I can iterate through all comments and get the latest through the timestamp, but is there another possibilty, as I don't want to loose performance?

TIA!!

2 answers

1 accepted

1 vote
Answer accepted
Antoine Berry Community Leader Nov 29, 2021

Hi @Sabrina F_ ,

To get the last comment of an issue : 

import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.getCommentManager()
def lastComment = commentManager.getLastComment(issue)

To get the last updated comment of an issue : 

import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.getCommentManager()

def comments = commentManager.getComments(issue).sort { it.getUpdated() }
def lastUpdatedComment = comments.last()

To get the comment body : 

String body = comment.getBody()

I am afraid that if you need the last updated comment, you need to sort at some point. 

Hope that helps.

And then, of course, restrict it to the corresponding comment-events for your use-case. If possible also restrict it to the projects to avoid unnessessary executions. Then your performance should be fine.

Thumbs up for thinking of performance, not everyone does!

Like Sabrina F_ likes this

Thank you very much for this fast answer, that's exactly what I was looking for!

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events