The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Send Custom Email with last comment from specific user

Deleted user
December 6, 2016

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

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
December 7, 2016

Hi Pon,

For a JIRA v6.* and SR v3.* try to use something like the script below in your email template

&lt;% 
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}&lt;br&gt;, Body: ${lastCommentFromUser.body} Created at: ${lastCommentFromUser.created} &lt;br&gt;&lt;br&gt;"
}
%&gt;
    
Last comment from user - ${userKey}: ${lastCommentString}

Please let me know if this does the trick

Deleted user
December 7, 2016

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"

 

&lt;% 
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}"
	} 	
} 
%&gt;
    
${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

Deleted user
December 7, 2016

@Thanos Batagiannis [Adaptavist]

 

I GOT IT!

Changed HTML to plain text (will convert to HTML later)

See following code: 

 

&lt;% 
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 &lt;&lt; lastCommentFromUser.last().body      
	else if (issueDesc)
        lastCommentFromUser = out &lt;&lt; issueDesc
		else lastCommentFromUser = out &lt;&lt; "" 
%&gt;

 

Thanks Thanos smile

0 votes
Deleted user
December 6, 2016

I succeeded in scripting the condition parameters:

&lt;% if (comments.authorKey[-1] == "customer.care")
    out &lt;&lt; comments.authorKey.getBody() == "customer.care" 
	else null %&gt;

But still stuck in getting the body of the comment, help please smile

 

many thanks, 

Pon

TAGS
AUG Leaders

Atlassian Community Events