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

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Class to write to CSV file(script runner )

Moses Thomas Community Leader Jan 05, 2021

Hello Adaptavist,

I have been looking for the class to use so that i can write results obtain from my script to CSV. but the script runner console does not recognize the class  mentioned here

does  any one  knows the right class ? script runner version(5.8.0-p5)

import org.apache.commons.csv.CSVPrinter

the above is not recognized by script runner ;/


Kind regards,


2 answers

1 accepted

0 votes
Answer accepted
Moses Thomas Community Leader Jan 18, 2021

@Leo   This  solution perfectly works in my case, i thought i could share,  the   library was just hard to find, but i found it.


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import // already available for use no need to import

FileWriter attFds = new FileWriter("/sbclocal/apps/jira_home/export/Item.csv")

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def query = jqlQueryParser.parseQuery("Project = XYZ")
def search =, query,PagerFilter.getUnlimitedFilter())


for (item in search.results)
def issue = issueManager.getIssueObject(

CustomField cf10977 = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10977")
String cf10977Value = issue.getCustomFieldValue(cf10977)
CustomField cf10911 = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10911")
String cf10911Value = issue.getCustomFieldValue(cf10911)
String summary = issue.getSummary()

if( cf10977Value == cf10911Value) {



1 vote
Leo Community Leader Jan 05, 2021

Hi @Moses Thomas,

I never tried but you can refer below articles for more details

// This is the CSV library Atlassian has built into Jira
// See

import com.mindprod.csv.CSVWriter

// Convert a list of maps to a CSV string
def mapsToCSV(mapList) {

// Get keys from all maps and build a header row
def headerSet = new LinkedHashSet()
mapList.each { headerSet.addAll(it.keySet()) }
def headers = headerSet.toArray()

def sw = new StringWriter()
def csv = new CSVWriter(sw)

// Add header row
headers.each {csv.put(it.toString())}

// Add rows - put in empty string if a header key doesn't exist in a row
mapList.each { row ->
headers.each {
csv.put(row.get(it)?.toString() ?: '')
return sw.toString()




@Leo   Thanks for the reply,  This  is not solution in my  case , i don't  need  to map lists / linked hash set. I just need to  write to csv  file  of some out put,  but i found  another way  and  i  need to  test it on the server and i  will give feed back once it worked.


Kind regards,


Suggest an answer

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

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

7,138 views 8 28
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