Forums

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

Is there a way to add all of the Comment History to an email?

Marques Butilla January 31, 2020

I am using a post function on my workflow to send an email with the entire comment history within the email. I have been trying this using scriptrunner, but I am only able to get the last comment of the ticket. Does anyone have any ideas on how to solve this?

2 answers

1 accepted

1 vote
Answer accepted
PD Sheehan
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.
January 31, 2020

What have you tried that only returned the last comment?

You should be able to use the commentManager and add all the comments to the body of your email. I would probably put them all in an Html table.

Here is a quick snipet I created for the console

import com.atlassian.jira.component.ComponentAccessor as CA
def issue = CA.issueManager.getIssueObject('JSP-1922')
def cm = CA.commentManager
def rm = CA.rendererManager

"""<table ><thead><tr><th>Author</th><th>Created</th><th>Comment</th></tr></thead><tbody>
${cm.getComments(issue).collect{
def renderedComment = rm.getRenderedContent('', it.body, issue.getIssueRenderContext())
"""<tr><td>$it.authorApplicationUser.displayName</td><td>$it.created</td><td>$renderedComment</td></tr>"""
}.join('')} </tbody></table>"""
Marques Butilla February 3, 2020

Hi Peter-Dave,

This is the code I am currently running in scriptrunner, the template I'm using is to send out emails with scriptrunner, as such it gives me errors when trying to use def and import.

Dear ${issue.assignee?.displayName},<br>
<br>
The following issue has been assigned to you.<br>
<br>
<b>Issue Key:</b> ${issue.key}<br>
<b>Issue Type:</b> ${issue.issueType.name}<br>
<b>Priority:</b> ${issue.priority?.name}<br>
<b>Assignee:</b> ${issue.assignee?.displayName}<br>
<b>Reporter:</b> ${issue.reporter?.displayName}<br>
<b>Epic Link:</b> <% out <<
(issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('Epic Link')).toString()) %>
<br>
<b>Story Points:</b> <% out <<
(issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('Story Points')).toString()) %>
<br>
<b>Due Date:</b>${issue.getDueDate() }<br>
<b>Sprint:</b> <% out <<
(issue.getCustomFieldValue(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('Sprint')).toArray()) %>
<br>
<b>Workflow Transitions:</b><br>
${getWorkflowButtons.call()}
<br>
<br>
<b>Summary:</b> ${issue.summary}<br>
<br>
<b>Description:</b> $issue.description<br>
<br>
<% if (mostRecentComment)
out << "<b>Last comment</b>: " << mostRecentComment
%><br>
<br>
Regards,<br>
${issue.reporter?.displayName}<br>
PD Sheehan
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.
February 3, 2020

Add the following to the "Condition and Configuration" script block

import com.atlassian.jira.component.ComponentAccessor as CA
def issue = CA.issueManager.getIssueObject('JSP-1922')
def cm = CA.commentManager
def rm = CA.rendererManager

config.renderedCommentsTable = """<table ><thead><tr><th>Author</th><th>Created</th><th>Comment</th></tr></thead><tbody>
${cm.getComments(issue).collect{
def renderedComment = rm.getRenderedContent('', it.body, issue.getIssueRenderContext())
"""<tr><td>$it.authorApplicationUser.displayName</td><td>$it.created</td><td>$renderedComment</td></tr>"""
}.join('')} </tbody></table>"""

true //or whatever your condition was

Then you can add the table to your template with

${config.renderedCommentsTable}

 

Also, since comments can be large and numerous ... you could limit to say... the last five comments by changing

${cm.getComments(issue).collect{

To 

${cm.getComments(issue).sort{it.created}.reverse().take(5).collect{

This will have the latest comment at the top. You can add another reverse after the take(5) to change the order.

Marques Butilla February 3, 2020

Thanks Peter-Dave, this works

0 votes
Jack Brickey
Community Champion
January 31, 2020

I am using JETI for this.

Suggest an answer

Log in or Sign up to answer