Hi,
I am trying to send at least the last comment in an email on transition.
I have tried the 3 solutions from : https://jamieechlin.atlassian.net/wiki/spaces/GRV/pages/33030148/Built-In+Scripts#Built-InScripts-CommentsinEmails
But every time, if there is only one comment, the email sent doesn't include the comment. (I tried lastComment, mostRecentComment
& latestPriorComment)
And if I create a second comment, it's sending the last comment as expected.
I can't find a way to send the comment if there is only one.
Any clue?
Dear $issue.reporter.displayName,
Your request has been refused for the following reason :
<% if (lastComment)
out << "Last comment: " << lastComment
%>
Don't hesitate to contact us for more explanation.
Best regards,
I finally figured it out. Still combine your solution with mine. Here is what I did (I had to change "def lastComment" by "config.lastComment") :
For "Condition and Configuration" on the send custom email :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.ApplicationUser
CommentManager commentMgr = ComponentAccessor.getCommentManager()
config.lastCustomComment = commentMgr.getComments(issue)?commentMgr.getComments(issue).last().body: ""
and for email template :
Dear $issue.reporter.displayName,
Your request has been refused for the following reason :
<% if (mostRecentComment)
out << mostRecentComment
else
out << lastCustomComment
%>
Don't hesitate to contact us for more explanation.
Best regards,
@Ravi Sagar _Sparxsys_ Thanks to your answer combine with what I had before, I made it work !!
I made it this way :
For "Condition and Configuration" on the send custom email :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.ApplicationUser
CommentManager commentMgr = ComponentAccessor.getCommentManager()
def lastComment = commentMgr.getComments(issue)?commentMgr.getComments(issue).last().body: ""
and for email template :
Dear $issue.reporter.displayName,
Your request has been refused for the following reason :
<% if (mostRecentComment)
out << mostRecentComment
else
out << lastComment
%>
Don't hesitate to contact us for more explanation.
Best regards,
Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually it's not working...
It's working on the preview mode but when published, still sending "null" when there is only one comment...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, you can try to setup logging to know more about why it is not working. You will get details where exactly it is failing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh, you don't need to add the code in the Condition and Configuration.
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.
You can fetch last comment using something like this.
CommentManager commentMgr = ComponentAccessor.getCommentManager()
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
def lastComment = commentMgr.getComments(issue)?commentMgr.getComments(issue).last().body: ""
You can take a look at this page to get more idea about how to fetch the last comment. There is a code there. Just modify the bits you don't need and use it in the post function.
Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the quick reply.
So I have set that in "Condition and Configuration" on the send custom email :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.user.ApplicationUser
CommentManager commentMgr = ComponentAccessor.getCommentManager()
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
def lastComment = commentMgr.getComments(issue)?commentMgr.getComments(issue).last().body: ""
And that in the email template :
Dear $issue.reporter.displayName,
Your request has been refused for the following reason :
<% if (lastComment)
out << lastComment
%>
Don't hesitate to contact us for more explanation.
Best regards,
But that sends the first comment posted and not the last one...
I will try to make something using your function if only one comment and the mostRecentComment otherwise.
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.