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?
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
}
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]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.