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

Scriptrunner listener last changed comment

Sabrina F_ November 29, 2021

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

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 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
1 vote
Sabrina F_ December 1, 2021

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

TAGS
AUG Leaders

Atlassian Community Events