Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

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.

Leonard Chew Community Leader Nov 30, 2021

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
Community showcase
Published in Jira

Do you use Jira Cloud with Microsoft Teams?

Hi, Jira users! Do you use Jira alongside Microsoft Teams? We want to hear how you’ve used the power of Jira Cloud and Microsoft Teams (via the Jira Cloud for Microsoft Teams app) to achieve a team...

122 views 0 5
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