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
https://commons.apache.org/proper/commons-csv/apidocs/org/apache/commons/csv/CSVPrinter.html
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,
Moses
@Leo This solution perfectly works in my case, i thought i could share, the java.io.FileWriter library was just hard to find, but i found it.
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.bc.issue.search.SearchServiceimport com.atlassian.jira.jql.parser.JqlQueryParserimport com.atlassian.jira.web.bean.PagerFilterimport com.atlassian.jira.issue.CustomFieldManagerimport com.atlassian.jira.issue.fields.CustomFieldimport java.io.FileWriter // already available for use no need to importFileWriter 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 = searchService.search(user, query,PagerFilter.getUnlimitedFilter())attFds.write("IssueKeys,IT,Summary")attFds.write("\n")for (item in search.results){ def issue = issueManager.getIssueObject(item.id) 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) { attFds.write("$issue,$cf10977Value,$summary") attFds.write("\n") } }
Hi @Moses Thomas,
I never tried but you can refer below articles for more details
http://mindprod.com/application/csv.manual.html#CSVWRITER
// This is the CSV library Atlassian has built into Jira// See https://wush.net/svn/mindprod/com/mindprod/csv/CSVWriter.javaimport com.mindprod.csv.CSVWriter// Convert a list of maps to a CSV stringdef 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())} csv.nl() // 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() ?: '') } csv.nl() } csv.close() return sw.toString()}
BR,
Leo
@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.
@Moses Thomas Can you add the solution to your case here?
It looks like you're new here. Sign in or register to get started.