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]
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 ($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()
#set ($c = $c - 1)
End Comment Code
The output I get is:
Begin Comment Code
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
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-->>
Commented by: $comment.authorApplicationUser.displayName<br/>
<td width="100%" bgcolor="#88898c" style="font-size:4px"<!--change the px value to change the size--> > </td>
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
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!
Badges are a great way to show off community activity, whether you’re a newbie or a Champion.Learn more
Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...
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!
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