I would like to include the full comment history for an issue when I send out an email update, with comments from youngest to oldest, like a typical email conversation. I'm thinking I'd have to run a foreach loop to print everything out, but I'm still a bit unclear as to how to reference the subclasses of the issue in order to retrieve the comments.
I'm reading through the Velocity and Jira docs to figure things out, but would would love to hear from anyone who has done this before and can point me in the right direction.
Ok, finally found out what to do. Posting the relevant code here for posterity. I'm not done modifying it for my own needs, but the basic functionality is there.
##Import the ComponentAccessor class #set ($componentAccessorClass = $constantsManager.getClass().getClassLoader().findClass('com.atlassian.jira.component.ComponentAccessor')) #set ($componentAccessorConstructor = $componentAccessorClass.getConstructor()) #set ($componentAccessor = $componentAccessorConstructor.newInstance()) #set($commentManager = $componentAccessor.getCommentManager() ) ##For Each loop which runs backwards through the issues (youngest to oldest) #set ($comments=$commentManager.getComments($issue)) #set ($c=$comments.size()) #foreach($comment in $commentManager.getComments($issue)) #set ($c = $c - 1) ## If statement filters out comments with a RoleLevel other than "all users" #if(!$comments.get($c).getRoleLevel()) - - - - - - - - - - - $comments.get($c).getBody() #end #end
Glad you got it working. From experience I recommend you only add the latest fifty comments and only the first 4096 characters to keep you email size smallish. Large emails can do bad things to JIRA performance
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.
Hello, this is working fine. My question if the user has to add a username in the comment, the format is shows is [~userName] but i would like to show it like "UserName,Testing"
how to add it that way?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Like @JudyS wrote, we were using the following to access the ComponentAccessor Instance in the email template velocity context:
#set ($componentAccessorClass = $constantsManager.getClass().getClassLoader().findClass('com.atlassian.jira.component.ComponentAccessor')) #set ($componentAccessorConstructor = $componentAccessorClass.getConstructor()) #set ($componentAccessor = $componentAccessorConstructor.newInstance()) #set ($commentManager = $componentAccessor.getCommentManager() )
In JIRA 6.4 the following issue was occuring using this:
duplicate class definition for name: "com/atlassian/jira/component/ComponentAccessor"
To get it back to work, we had replace it with the following:
#set ($componentAccessor = $constantsManager.getClass().forName('com.atlassian.jira.component.ComponentAccessor').newInstance()) #set ($commentManager = $componentAccessor.getCommentManager() )
So the example for appending the entire mail history will be:
#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) #set ($comments = $commentManager.getComments($issue)) #set ($c = $comments.size()) #foreach($comment in $commentManager.getComments($issue)) #set ($c = $c - 1) ## If statement filters out comments with a RoleLevel other than "all users" #if(!$comments.get($c).getRoleLevel()) - - - - - - - - - - - $comments.get($c).getCreated() - $comments.get($c).getAuthorFullName() $comments.get($c).getBody() #end #end
Note that the standard template will show the comment on the event on top of the mail body. So with this addition it will be shown a second time.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Any tips for doing this on the HTML templates?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I got this code working up to JIRA6.2. Now I'm migrating to JIRA6.4, and this always produces this error with the first line of code:
An error occurred whilst rendering this message. Please contact the administrators, and inform them of this bug. Details: ------- org.apache.velocity.exception.MethodInvocationException: Invocation of method 'findClass' in class org.apache.catalina.loader.WebappClassLoader threw exception java.lang.LinkageError: loader (instance of org/apache/catalina/loader/WebappClassLoader): attempted duplicate class definition for name: "com/atlassian/jira/component/ComponentAccessor" at templates/email/html/includes/fields/comments-history.vm[line 12, column 86] at org.apache.velocity.runtime.parser.node.ASTMethod.handleInvocationException(ASTMethod.java:351) at ...
Have anyone tried with JIRA6.4? If yes, did you get the same error and did you fix it?
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, I've come a little further with this issue. The comments are printing out in the order I want. However, I can't seem to enforce the security settings per comment, so they all get added, even the private ones. I am trying to retrieve the Group Level settings via: $comment.getGroupLevel(), but no value is ever returned. $comment.getBody() works just fine. Any idea why this could be?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Judy,
I believe that if you change the mail handler for adding comments to "Add a comment with the entire mail body" you'll achieve the result you want. Please check the following link for further information:
Thanks and regards,
Paula Silveira
Atlassian Support | Cloud
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Paula,
I'm actually trying to change the template for an outgoing email. Basically, I want an outgoing email summary to be created on a "comment added" event that looks something like this:
Current Comment
-----
Comment 3
-----
Comment 2
-----
Comment 1
-----
Description
Then when someone replies to the email, then only their reply should be taken in as the next comment (that part should be easy with the right mail handler settings).
Make sense?
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.