Hello,
Im having big troubles trying to get the last comment from a specific user to be sent with the custom email.
Here is the code i currently have:
<p><% if (mostRecentComment) out << "<p>------Response Message------</p>" << "\n" << "\n" << mostRecentComment << "</p>" else if (issue.description) out << "<p>------Original Message------</p>" << "\n" << "\n" << "<p>" << issue.description << "</p>" else null %>
The issue with the above is that it will send the last comment in the ticket, how can i modify this code to send "lastComment" from a specific user?
i tried to use this following code:
<% out << comments.authorKey[-1] == "customer.care" %>
But its pulling currentuser name.
Many thanks! and i really appreciate your help.
Cheers,
Pon
Hi Pon,
For a JIRA v6.* and SR v3.* try to use something like the script below in your email template
<% def userKey = "admin" def commentManager = com.atlassian.jira.component.ComponentAccessor.getCommentManager() def comments = commentManager.getComments(issue) def lastCommentString = "No comments made from user ${userKey}" def commentsFromUser = comments?.findAll {it.authorApplicationUser.key == userKey} if (commentsFromUser) { def lastCommentFromUser = commentsFromUser.last() lastCommentString = "Author: ${lastCommentFromUser.authorFullName}<br>, Body: ${lastCommentFromUser.body} Created at: ${lastCommentFromUser.created} <br><br>" } %> Last comment from user - ${userKey}: ${lastCommentString}
Please let me know if this does the trick
Hi @Thanos Batagiannis [Adaptavist]
Thanks for your quick reply, and i will do tag correctly next time.
Here is the following code i implemented, it works fine when previewing, but when i put it into operation within post function, i receive an error:
"Property 'cfValues['Email Address']' not found", when i remove this, it will then force another error "'lastCommentFromUser' not found"
<% def userKey = "customer.care" def commentManager = com.atlassian.jira.component.ComponentAccessor.getCommentManager() def comments = commentManager.getComments(issue) def lastCommentString = "No comments made from user ${userKey}" def lastCommentFromUser = comments?.findAll {it.authorApplicationUser.key == userKey} if (lastCommentFromUser) { lastCommentFromUser = lastCommentFromUser.last() if (lastCommentFromUser) { lastCommentString = "From: ${cfValues['Email Address']}\nSent:${lastCommentFromUser.created}\nTo: test@testenviroment.com.au\nSubject: ${cfValues['Email Subject']}\n\n${lastCommentFromUser.body}" } } %> ${lastCommentString}
Also more information about JIra, im currently using JIRA 6.3.3 and scriptrunner version 3.0.5
Many many thanks for your help.
Pon
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Thanos Batagiannis [Adaptavist]
I GOT IT!
Changed HTML to plain text (will convert to HTML later)
See following code:
<% def userKey = "customer.care" def commentManager = com.atlassian.jira.component.ComponentAccessor.getCommentManager() def comments = commentManager.getComments(issue) def lastCommentFromUser = comments?.findAll {it.authorApplicationUser.key == userKey} def issueDesc = issue.description if (lastCommentFromUser) lastCommentFromUser = out << lastCommentFromUser.last().body else if (issueDesc) lastCommentFromUser = out << issueDesc else lastCommentFromUser = out << "" %>
Thanks Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I succeeded in scripting the condition parameters:
<% if (comments.authorKey[-1] == "customer.care") out << comments.authorKey.getBody() == "customer.care" else null %>
But still stuck in getting the body of the comment, help please
many thanks,
Pon
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.