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?
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>"""
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>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.