Jira export bulk comments with Scripted fields

Samuel April 29, 2015

Hi, 

I want to export bulk issue with "all comments" with author name to excel sheet, and i used scripted field with following script:

import com.atlassian.jira.component.ComponentAccessor
def comments = ComponentAccessor.commentManager.getComments(issue)
if (comments) {
comments.body
}

It does the job, but it brings all the comments together in one line. Can someone please help to break each comments in to new line with author's name on the top of each comment?

I also tried to add the author name with following code:

comments.authorFullName

but it removes the comment and display only author's name.

Can someone please help me to achieve both (all comments with author's name) with clean format?

4 answers

2 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 29, 2015

The variable you generate called "comments" is a list of objects, not a simple block of text.  It's one object per comment on the issue.  When you just splat it out into the result by saying comments.body, java is effectively taking a bit of a punt and assuming you want "recognisable text from the objects in this list"

What you need to do is iterate over the list, and pull what you need.  The pseudocode in my head is to replace comments.body with

  • Create a variable called something like results.  Needs to be able to hold a lot of text
  • for each $item in $comment {
    • add item.getUpdateAuthorFullName() to results 
    • add item.getUpdated() to results
    • add item.getBody() to results
    • add some separator string to results
    • }
  • And finally, return the results variable.

 

0 votes
Ash
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 Leaders.
February 4, 2019

@Samuel did you figure how to script this??

0 votes
Midori
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 Leaders.
November 17, 2015

You can flexibly export comments to Excel with the Better Excel Plugin.

It represents comments with its own calculated fields concept, which doesn't require you actually creating custom fields in JIRA, just adding a couple of Groovy lines that define the value, type (numeric, text) and format (for numbers and dates) of the field.

Albeit you are welcome to create new calculated fields or modify the existing ones, these are available out of the box:

Excel commentsText, user and date of all comments.
It is a longer block of text that can be inserted into a single Excel cell. If you need only the first or last comments, and more granularity, see the next items.
Excel first commentText, user and date of the first (earliest) comment.
It is a block of text that can be inserted into a single Excel cell. If you need more granularity or better data types, see the next 3 items.
Excel first comment textThe actual text of the first comment.
Excel first comment userThe user who added the first comment.
Excel first comment dateThe date when the first comment was added.
Excel last commentText, user and date of the last (latest) comment.
It is a block text of that can be inserted into a single Excel cell. If you need more granularity or better data types, see the next 3 items.
Excel last comment textThe actual text of the last comment.
Excel last comment userThe user who added the last comment.
Excel last comment dateThe date when the last comment was added.

You should be able to achieve what you want with zero or little work.

0 votes
Samuel April 29, 2015

@Nic Brough [Adaptavist] Since you are most active one that I know through the atlassion support tickets, can you please help?

Suggest an answer

Log in or Sign up to answer