Hello,
Is it possible to create a calculated text field that holds all the comments of that issue, each one started on an new line with the date and author in front of that comment?
If yes, what would be the code I have to enter in the description field?
Thank you,
Wouter
You can start from the following snippet:
<!-- @@Formula: import com.atlassian.jira.issue.comments.CommentManager; CommentManager commentManager = com.atlassian.jira.ComponentManager.getComponent(CommentManager.class); StringBuilder s = new StringBuilder(); for (com.atlassian.jira.issue.comments.Comment c : commentManager.getComments(issueObject)) { s.append(c.getCreated().toString()); s.append("\r"); s.append(c.getBody()); s.append("\r"); } return s.toString(); -->
Hello David,
This does the tric, thanks for that.
The only thing that isn't working is the append("\r"): both in Jira (5.2.4.1) as in the excel view, the concatenated string is on a single line. I suppose for the Excel view we would need something like "ALT-ENTER" ?
Another question: how can I change the format of .getCreated()? Now it shows for instance "Wed Feb 12 16:39:05 CET 2014". For our purposes, it suffices to show just "12/02/2014".
And finally: can I add also text formatting to this string (for instance: date in bold) I have tried this by appending Jira text effects to the string (*.....*), but this doesn't seem the way to go.
Thank you,
Wouter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm afraid the line breaks won't work correctly until I fix your last issue, which is related to the fact that Calculated Text Fields currently cannot use the wiki renderer. I'll fix that in the next version.
As for formatting dates, you can use the following:
<!-- @@Formula: import com.atlassian.jira.issue.comments.CommentManager; import org.joda.time.DateTime; CommentManager commentManager = com.atlassian.jira.ComponentManager.getComponent(CommentManager.class); StringBuilder s = new StringBuilder(); for (com.atlassian.jira.issue.comments.Comment c : commentManager.getComments(issueObject)) { s.append( new DateTime( c.getCreated()).toString("dd/MM/yyyy")); s.append("\r\n"); s.append(c.getBody()); s.append("\n"); } return s.toString(); -->
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks David!
Question can be closed as far as I'm concerned.
Wouter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David, I have used your code and it works well. However, it does not show the name or ID of the user who logged the comments. Is there a way to achieve the same? I looked up the CommentManager and also tried getCommentsForUser(), but it doesn't work. Will appreciate your help! -- Bharat K
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Since "c" in the loop above is a Comment object, you can use c.getAuthorApplicationUser().getUsername() for the username, or c.getAuthorApplicationUser().getDisplayName() for the full name.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks David. That did not work :) But the fault is mine. I should have mentioned that we are using v5.0.1 currently. The ApplicationUser class, of which getUsername() or getDisplayName() are the methods, is available from v5.1.1 onwards. However, I used c.getAuthorFullName() and it works just fine. We are planning to move shortly to v6.4.x or v7. When we do that, I'll have to change this call to what you have mentioned. But for now, it works like dream ! -- Bharat K
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello David,
I did not find any errors with "com.innovalog.jmcf"
I did find some errors with "innovalog", they all look like this:
2014-04-24 13:38:03,557 JiraTaskExectionThread-2 ERROR 35kvae 811x2157x1 1vjc0qj 10.1.130.106 /secure/admin/jira/IndexReIndex.jspa [innovalog.jmcf.fields.CalculatedNumberField] CalculatedNumberField: error evaluating formula: Sourced file: inline evaluation of: `` issue.get("customfield_11604") * issue.get("customfield_11605") * issue.get("cu . . . '' : illegal use of null value or 'null' literal
They are not related to the custom calculated field I'm reffering to (which is "customfield_11700" and is not using any other custom fields).
Best regards,
Wouter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, if you're not getting any error, then I don't know. Try first replacing the formula with a simlpe constant to make sure that works, and then try re-adding code step-by-step until it breaks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello David,
I tried your suggestion, and strangly, after re-adding all the original code, it still works. Probably a user error from my part.
I have an additional question with regards to formatting calculcated text fields, but I'll post this in a seperate topic.
Thanks,
Wouter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you look inside atlassian-jira.log for errors? Look for "com.innovalog.jmcf"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello David,
We are moving to JIRA 6.1.6. The simple calculated fields I create myself still work, but the one you created for me in the answer here above does not.
Do you have any idea what I need to change to make it work again?
Thank you,
Wouter
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.