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

Display last comment using Script Runner

Hi,

I need to display last comment in customfield using Groovy Script.

Anyone done that?

3 answers

Put below code under custom "scripted field" 

 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager

import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.getCommentManager()

def comment = commentManager.getLastComment (issue)

comment.body 

Hi Tukaram,

 

is it possible to add user name who commented on this along with comment?.

Yes , use below code

 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager

import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.getCommentManager()

def comment = commentManager.getLastComment (issue)

comment.body + " Author: " + comment.authorFullName

Like Eusebio Ajenjo likes this

Thank you, Tukaram.

Thanks, Tukaram

Hello, 


First of all thank you, however how can I add error handling on it? when an issue is created the field starts throwing up a lot of error messages in the logs as there is no comment yet. 

Try below one

def comment = commentManager.getLastComment (issue)

if(comment != null)
{
comment.body + " Author: " + comment.authorFullName
}

Like Евгений Баев likes this

Thanks, that worked beautifully.

It works like a charm! Thank you very much Tukaram Bhukya.

Is there a way to show only the last internal comment?

Hello Jan:

In this question you will find an asnwer on how to get a comment from an Issue Object. Afterwards you can iterate to find the latest one, or find the one with the latest date.

If this doesn't work for you, let us know and I'll program a 1 on 1 meeting with you to get it working.

Cheers!

Hi, Any idea if and how can I re-render the wiki style render ?

Lots of comments contain formatting and user mentions , new lines, bullets are not formatted at all.

Try this, it works but i found that my Database usage spiked after using it. 

https://community.atlassian.com/t5/Jira-questions/Scripted-Field-to-copy-latest-comment/qaq-p/51850

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Watch Slack + Atlassian's Webinar: “Transform cross-functional collaboration with Slack + Atlassian

Hi Atlassian Community! We recently partnered together with Slack on a webinar, “ Transform cross-functional collaboration with Slack + Atlassian ”. Building fast, growing exponentially: all...

32 views 0 2
Join discussion

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