Comments History in Notification Email Jira 7.2.7 Edited

I am testing a plugin to use with Jira called TemplateMe! which allows us to use templates for each notification event. The templates support HTML, rich text and also Velocity.

We are on Jira version 7.2.7

We are using this as we have a single instance with multiple projects and want to send out different templates for each project.

One of the requests was on comments notification to include a history of previous comments in addition to the last comment.

The last comment was simple enough and there was already example code provided using $lastComment.getBody() along with an #if check 

I also was able to get all comments to display using $comments, but my output looked like this:

Begin Comments Code
[com.atlassian.jira.issue.comments.CommentImpl@e96452a3, com.atlassian.jira.issue.comments.CommentImpl@55559a42, com.atlassian.jira.issue.comments.CommentImpl@142091e4, com.atlassian.jira.issue.comments.CommentImpl@553efd93, com.atlassian.jira.issue.comments.CommentImpl@c23697a8, com.atlassian.jira.issue.comments.CommentImpl@fbac6072, com.atlassian.jira.issue.comments.CommentImpl@61774608, com.atlassian.jira.issue.comments.CommentImpl@9721f59d, com.atlassian.jira.issue.comments.CommentImpl@6c8bd8af, com.atlassian.jira.issue.comments.CommentImpl@afd249be, com.atlassian.jira.issue.comments.CommentImpl@19283849, com.atlassian.jira.issue.comments.CommentImpl@a11008ce, com.atlassian.jira.issue.comments.CommentImpl@26b03b60, com.atlassian.jira.issue.comments.CommentImpl@818e558b, com.atlassian.jira.issue.comments.CommentImpl@ea1efdf2, com.atlassian.jira.issue.comments.CommentImpl@3cbc606a, com.atlassian.jira.issue.comments.CommentImpl@cb8b924e, com.atlassian.jira.issue.comments.CommentImpl@ad9dec91, com.atlassian.jira.issue.comments.CommentImpl@86ba8c2f, com.atlassian.jira.issue.comments.CommentImpl@6c749d9, com.atlassian.jira.issue.comments.CommentImpl@5f38c6c0, com.atlassian.jira.issue.comments.CommentImpl@69efcd52, com.atlassian.jira.issue.comments.CommentImpl@e676b1f2]
23
End Comment Code

I was not able to get the actual text body or the author, in the same way, I could the $lastComment.getBody() or $lastComment.getAuthorApplicationUser().getName()

I searched the community and found a solved example from Jira 6.3 and there, I also found the updated code for 6.4. I tried this code out and I was unable to get anything other than to see the size of $comments just to check

Below is the code, with some evaluation code I put in to see where it is failing. (I am using HTML comments instead of velocity as I am working in HTML environment for the general template design)

<td colspan="2" align="left" style="padding-left:5px; font-weight:bold; font-size:14px;">
Begin Comments Code<br/>

<!--Import the ComponentAccessor class 6.4 -->
#set ($componentAccessor = $constantsManager.getClass().forName('com.atlassian.jira.component.ComponentAccessor').newInstance())
#set ($commentManager = $componentAccessor.getCommentManager() )

<!--For Each loop which runs backwards through the issues (youngest to oldest) skipping the most recent, since it is already shown above -->
#set ($comments=$commentManager.getComments($issue))
#set ($c=$comments.size())
#evaluate($c)<br/>
#set ($c = $c - 1)

#foreach($comment in $commentManager.getComments($issue))
The Loop is on this iteration: $velocityCount <br/>
$com.get($c).getCreated() - Commented by:$com.get($c).getAuthorFullName()
$com.get($c).getBody()
#set ($c = $c - 1)
#end

End Comment Code
</td> 

The output I get is:

Begin Comment Code

28  

End Comment Code

*note the number above does update on each comment so I know that $comments.size() is working

Since I am never getting the text:

The Loop is on this iteration:

I take it to mean that the loop exits immediately and that the $commentManager.getComments($issue) must not be pulling any comments

Any help with what might be wrong or if there is an easier way to simply format the comments output I received above would be great.

Thank you and my apologies for the long read

1 answer

Please close, I was able to get it much simpler as it seems importing the class is not needed

Edit: If anyone else needs to create a comments history here is the code for a table separated history including author and time stamp.

Each comment generates is in its own table formatting, nested into additional parent tables

Earlier styling in my code keeps the parent table constrained to a size that is mobile friendly so anyone getting notifications on their mobile device will be happy.

Each comment using this code is separated using a colored (grey) bar

 #set($c = $comments.size())
#foreach($comment in $!comments)
#set($c = $c - 1)
#set ($comment = $!comments.get($c))
<table <!--Add your own styling here-->>
<tr>
<td>
<br/>
Date: $comment.created<br/>
<br/>
Commented by: $comment.authorApplicationUser.displayName<br/>
<br/>
$comment.body<br/>
</td>
</tr>
<tr>
<td width="100%" bgcolor="#88898c" style="font-size:4px"<!--change the px value to change the size--> >&nbsp;</td>
</tr>
</table>
#end

 

Hi,

We are trying to show the comment history in our notifications.  Which Velocity template did you add this section to?

Thanks

Hi Jim,

I apologize that I missed your question. Hopefully, you have found a solution already. My code above is for the templateme! plugin and would not work in the normal velocity templates. This plugin ended up not working for me, so I gained access to modify the velocity templates.

If you do still need help, I found another answer for the comments history in the community

https://community.atlassian.com/t5/Jira-questions/Change-email-template-to-show-comment-history/qaq-p/96633

If you are on 6.4 or newer (im on 7.2 and it works) scroll down to find the code block provided by another user

I adapted it with html tables to get the same desired result as I did above with the templateme!

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

301 views 1 4
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you