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

Get all JIRA comments to a ScriptRunner Field Edited

I need to be able to view all the comments on an issue, with the date and author in a scripted field. 

I was trying to play around with this but could not figure out how to get it to work for all comments: 

import com.atlassian.jira.component.ComponentAccessor

def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def commentManager = ComponentAccessor.getCommentManager()
def rendererManager = ComponentAccessor.getRendererManager()
def comments = commentManager.getCommentsForUser(issue, user)

if (comments) {
def commentAuthor = comments.last().getUpdateAuthorFullName()
def commentDate = comments.last().getUpdated()
def commentBody = rendererManager.getRenderedContent("atlassian-wiki-renderer", comments.last().body, issue.issueRenderContext)

return "<p><span style=\"font-size:smaller;color:#a9a9a9;font-style:italic\">" + commentDate.format('YYYY-MM-dd') + " | " + commentAuthor + commentBody + "</span></p>"


Can anyone help? 

1 answer

Hi @Allyson Norris 

This script will print all comments for a given issue, I hope it will help you :)

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger;
import org.apache.log4j.Level;


def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueObject("SD-47")
def commentManager = ComponentAccessor.commentManager
def comments = commentManager.getComments(issue)

comments.each { comment ->"Date: " + comment.getCreated().format("dd/MM/yy") + ", Author: " + comment.getAuthorApplicationUser().getUsername() + ", Comment: " + comment.getBody())

Thank you! So I tried this script but when I put it in the field it tells me that the Variable "issue" masks a binding variable of the same name. So I change it to "issues" and then this is what is returned in the custom scripted field on the ticket: 

[com.atlassian.jira.issue.comments.CommentImpl@634b9de5, com.atlassian.jira.issue.comments.CommentImpl@c9783c53]

Suggest an answer

Log in or Sign up to answer

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