Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Get all JIRA comments to a ScriptRunner Field

Allyson Norris June 30, 2020

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

0 votes
Mathis Hellensberg
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.
July 1, 2020

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;

log.setLevel(Level.DEBUG);

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

comments.each { comment ->
log.info("Date: " + comment.getCreated().format("dd/MM/yy") + ", Author: " + comment.getAuthorApplicationUser().getUsername() + ", Comment: " + comment.getBody())
log
}
Allyson Norris July 1, 2020

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