Jira export bulk comments with Scripted fields

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?

3 answers

2 votes

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.

 

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

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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 16, 2018 in Jira

Looking for anyone who made the switch to Data Center

The Jira Marketing team is putting together an ebook on migrating to Data Center. We're looking for pro tips on how you staffed your project team and organized your Proof of Concept. Share yo...

83 views 0 4
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you