Forums

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

How to send all Issue comments via custom Email using script runner

Bunty
Contributor
October 2, 2019

Hello All,

How to display all comments in custom email using script runner.

Thanks in advance,

Bunty

3 answers

1 accepted

0 votes
Answer accepted
Gezim Shehu [Communardo]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 4, 2019

Weird... I though I already posted the answer, now that I check it doesnt show up.

 

Here

 

<%
def commentManager = com.atlassian.jira.component.ComponentAccessor.getCommentManager()
def comments = commentManager.getComments(issue)
for(comment in comments){
out << comment.body + "\n"
}
%>
Bunty
Contributor
October 4, 2019

Thanks Shehu. It is working and i can see comments in sequence.

author.PNG

 

Sorry, I am new to scripting so i am confused in making changes to script. 

One last question, can we retrieve author name and date in comments?

Thanks again,

Manikanta 

Gezim Shehu [Communardo]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 7, 2019

Glad to help.

Sure, to display the author you could use

 

<%
def commentManager = com.atlassian.jira.component.ComponentAccessor.getCommentManager()
def comments = commentManager.getComments(issue)
for(comment in comments){
out << "Comment by: " + comment.getAuthorApplicationUser().getDisplayName() +"\n"
out << comment.body + "\n"
}
%>
0 votes
Gezim Shehu [Communardo]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 4, 2019

@Bunty  in that case you can use something like this

 

<%
def commentManager = com.atlassian.jira.component.ComponentAccessor.getCommentManager()
def comments = commentManager.getComments(issue)
for(comment in comments){
out << comment.body + "\n"
}
%>

 

"<% %>" allows you to escape the GString template and run native Groovy code.

PS I'm writing in a separate answer, so this can be marked as accepted.


Cheers

Sandhya September 22, 2020

Hi Shehu,

able to get the comments but all the comments getting in single line by using below

<%
def commentManager = com.atlassian.jira.component.ComponentAccessor.getCommentManager()
def comments = commentManager.getComments(issue)
for(comment in comments){
out << comment.body + "\n"
}
%>

example: getting like this 

Comment1 comment2 comment 3

 

But i want every comment in next line as below

Comment1

Comment2

Comment 3

Kindly help on this

Sandhya September 22, 2020

@Gezim Shehu [Communardo] 

 

Please can you guide me on above , all the comments should get in next Line

 

Regards,

Sandhya

0 votes
Gezim Shehu [Communardo]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 3, 2019

This should return all comments of an issue

def commentManager = ComponentAccessor.getCommentManager()

def comments = commentManager.getComments(sourceIssue)
Bunty
Contributor
October 3, 2019

Hi Gezim,

Thanks for the reply.

Does the script work in Email Template to retrieve all comments?

Currently, i am using below script in Custom Email template in post function to display last comment in Email:

<% (transientVars?.comment)
out << transientVars.comment
%>

Thanks in advance,

Bunty

Gezim Shehu [Communardo]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 3, 2019

In that case $comments.body - will return a list of strings (comment bodies)

Bunty
Contributor
October 3, 2019

Thanks Shehu. It worked but it not in sequence all comments in one line.

comment.PNG

Is it possible to restive date and time like sequence in the below:

 CommPNG.PNG

Thanks in advance,

Bunty

Suggest an answer

Log in or Sign up to answer