Dear all,
I'm trying to build in a postfunction a jmwe-scripted field to get all comments stored in an pretty view, so that it can be used at the end of a transition to be added to a mail.
I'm trying:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.component.ComponentAccessor
def commentManager = ComponentAccessor.getCommentManager()
def comment = issue.get("comment")
comment.body
However this only results into an array-list-ouput listing all comments in a line separated by comma. This is not really user-friendly.
I'm new to jira-groovy-stuff, so any help would be highly appreciated. Imho in my above expression there is "only" missing a loop to bring the arraylist in a nice string- or even better a html-format?!
Thank you in advance! ;-)
PS. we only have jmwe but no script runner.
Hi Mario,
I'm not sure I understand where you want to put this script. JMWE doesn't offer "scripted fields" - but JMCF does. Which one are you using?
Also, you're trying to use that "field" in an email. How are you sending the email? Using a JMWE Email Issue post-function?
It is indeed possible to format the comments, but it depends on where exactly you want to use the result.
Dear David,
first of all thanks a lot for the fast reaction.
And please excuse my unclear question and my incorrect choice of words.
I have a simple custom field: "InternalFieldCommentToMailbody" - Text Field (multi-line)
And in a workflow I want to use a postfunction of a transition to fill that field by using the function: "Set field value (JMWE add-on)". In this postfucntion I have entered above code, which results into filling the text field with all comment contents but with the "wrong" unusable format.
At the end of the transition there is another postfunction named "Email issue (JMWE add-on)". And there in the "html-body" I want to use the prefilled textfield by a simple html format:
<ul>
<li>
<b>All Comments:</b> <br>
${issue.getAsHtml("InternalFieldCommentToMailbody")}</li> <br>
</ul>
I hope it is clearer now. ;-)
Thank you very much.
Best regards
Mario
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mario,
thanks, I got it now.
You first need to use the "wiki renderer" for your InternalFieldCommentToMailbody custom field. This is done in the Custom Field Scheme (see https://confluence.atlassian.com/adminjiraserver/configuring-renderers-938847270.html)
Then use this Groovy script to append all comments into the field:
issue.get("comment").collect{it.body}.join('\n')
However, if all you want is to include the comments in the Email body, you don't need to create that custom field. Instead, use this in the HTML body:
<b>All Comments:</b> <br>
<ul>
<%= issue.get("comment").collect{"<li>"+it.bodyHtml+"</li>"}.join('\n') %>
</ul>
although I'm not sure why you'd want to put them in a UL (a list)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear David,
thank you for your help. Your last code lines are exctaly what I was searching for. Will delete the custom field.
The listing is necessary as the complete email should include more information. I will go ahead with this formatting:
<ul>
<li><b>Summary:</b> ${issue.getAsHtml("summary")}</li> <br>
<li><b>Issuekey:</b> $issue.key</li> <br>
<li><b>Priority:</b> ${issue.getAsHtml("priority")}</li> <br>
<li><b>Reporter:</b> $issue.reporter</li> <br>
<li><b>Created Date:</b> $issue.created</li> <br>
<li><b>Description:</b> <br> ${issue.getAsHtml("description")}</li> <br>
<dl>
<dt><b>All Comments:</b></dt>
<br> <%= issue.get("comment").collect{"<dd><li>"+it.bodyHtml+"</li></dd>"}.join('\n') %>
</dl> <br>
</li>
</ul>
I've changed your html-code a little so that the output of the comments is now sorted very nice and engaged.
Btw does your postfunction "Email issue (JMWE add-on)" also include the possibility to attach the real attachments of an issue (not a link to the attachments) to the mail as well? Will ofc mark the answer as accepted in anyway! ;-)
Best regards
Mario
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mario,
I'm glad it works.
Regarding your question about attachments, you'll have to wait for JMWE 6.3.0, which should come out within a week :)
Regards,
David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello folks
This solution has saved me!
Is there a possibility to filter only public comments in the email? I do not want comments restricted by group or role to be sent
Thank you in advance!
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.