Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,559,017
Community Members
 
Community Events
184
Community Groups

Jira Comment Export using Script Runner

We have script runner piad add on installed in our Jira Data Center. It provides a lot of functionalities out of the box that doesn't natively exist in Jira.
Just wondering if it can help in export of issues from jira in csv format, etc. where comments can be exported under one single column. By default comments get exported in separate columns which is each comment has its own column of its own and it becomes tedious to concatenate them later in excel.
I tried the below script but it doesn't work :-

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Level


// The JQL query you want to search with
final jqlSearch = "project = UBT AND issuetype = Task"

// Some components
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def searchService = ComponentAccessor.getComponentOfType(SearchService)

// Parse the query
def parseResult = searchService.parseQuery(user, jqlSearch)
if (!parseResult.valid) {
log.error('Invalid query')
return null
}

try {
// Perform the query to get the issues
def results = searchService.search(user, parseResult.query, PagerFilter.unlimitedFilter)
def issues = results.results

issues*.key

issues.each { issue ->


def commentManager = ComponentAccessor.commentManager
def comment = commentManager.getComments(issue)
if (comment) {
comment.body
}

}

FileWriter attFds = new FileWriter("/jira_home/issues.csv")

attFds.write("COLUMN 1,COLUMN 2,COLUMN 3 \r\n")
attFds.close()


}
catch (SearchException e) {
e.printStackTrace()
null
}

 

All i would like to do is the below :-
Instead of doing the default native jira export of issues for a given JQL (includes all fields) where comments get exported in csv file in separate columns (each comment for each issue key in a separate column), i would like to do same export for the issues for a certain number of fields including comments but the export to a csv file should have all comments for a given issue key under one single comments column in a proper readable format. I am also fine just doing export of issue keys with its respective comments so i can merge them later into natively exported csv from jira that has all fields by deleting comments column and pasting the results for comments for the csv outputted via script runner against each issue key if that helps.

Thanks!

 

1 answer

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Sep 09, 2022

Are you suggesting concatenating ALL comments for a single issue into a single string to be placed in a single cell for a given issue?

That could quickly exceed the size limit from just about any system that you might use to read that cell.

But if you really need to, you could try something like this:

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.datetime.DateTimeFormatterFactory
import com.atlassian.jira.datetime.DateTimeStyle
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Level

// The JQL query you want to search with
final jqlSearch = "project = UBT AND issuetype = Task"

// Some components
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def searchService = ComponentAccessor.getComponentOfType(SearchService)
def commentManager = ComponentAccessor.commentManager
def jiraDateFormatter = ComponentAccessor.getComponent(DateTimeFormatterFactory).formatter().withStyle(DateTimeStyle.DATE_TIME_PICKER)

// Parse the query
def parseResult = searchService.parseQuery(user, jqlSearch)
if (!parseResult.valid) {
log.error('Invalid query')
return null
}

try {
// Perform the query to get the issues
def results = searchService.search(user, parseResult.query, PagerFilter.unlimitedFilter)
def issues = results.results
FileWriter attFds = new FileWriter("/apps/dev/jira-home/log/issues.csv")
attFds.write('Key,Summary,Reporter,Assingee,Created,Updated,Comments\r\n')
issues.each { issue ->
def comments = commentManager.getComments(issue)
def combinedComments = comments.collect { comment ->
"$comment.authorApplicationUser.displayName ($comment.authorApplicationUser.name) - ${jiraDateFormatter.format(comment.created)}:\n$comment.body"
}.join('\r\n\r\n')
attFds.write(issue.key + ',')
attFds.write(/"$issue.summary",/)
attFds.write(/"$issue.reporter.name",/)
attFds.write(/"$issue.assignee.name",/)
attFds.write(/"${jiraDateFormatter.format(issue.created)}",/)
attFds.write(/"${jiraDateFormatter.format(issue.updated)}",/)
attFds.write(/"${combinedComments.replaceAll('"', '""')}"/)
attFds.write('\r\n')
}
attFds.close()
} catch (SearchException e) {
e.printStackTrace()
null
}

Thanks a lot! That worked!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events