It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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"
}
%>

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 

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

This should return all comments of an issue

def commentManager = ComponentAccessor.getCommentManager()

def comments = commentManager.getComments(sourceIssue)

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

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

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

0 votes

@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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

334 views 1 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you