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

Display last comment using Script Runner

Hi,

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

Anyone done that?

6 answers

1 accepted

0 votes
Answer accepted
Daniel Yelamos [Adaptavist]
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.
May 19, 2017

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!

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 

Ash
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.
Jul 17, 2017

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 # people like this
Ash
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.
Jul 18, 2017

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. 

Like vasanth likes this

Try below one

def comment = commentManager.getLastComment (issue)

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

Like # people like this

Thanks, that worked beautifully.

Like vasanth likes this

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

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

Like Markus Pöhler likes this

I can't see a scripted field option? How do I make this work with a Script Listener to populate a custom field I made called: "Last Comment"

this worked great for me.  is there a way to break up the  "+ comment.authorFullName" to just show first name instead of 'last,first' ?

Hi,

Just want to see is there way to show the last comment without any inline images in the comment body? Thanks.

Is it possible to have this script only show the last comment of the reporter or the assignee ? 

Small update

Replace 

import com.atlassian.jira.ComponentManager

with 

import com.atlassian.jira.ComponentAccessor

 

import com.atlassian.jira.ComponentAccessor
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, 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

can we get latest comment to the previous comment details. 

Like vasanth likes this

Suggest an answer

Log in or Sign up to answer