Export CSV from Cases
NOTE
This tutorial follows the CSV Import tutorial.
The Export CSV application is runnable in the Demo environment or in your own instance of .
To learn how to install NAE CE locally or on a server, follow this tutorial.
CSV export code snippet
groovy
import com.netgrif.application.engine.petrinet.domain.dataset.FileField
import com.netgrif.application.engine.workflow.domain.QCase
import com.netgrif.application.engine.workflow.domain.Case
def exportCSVFile(String net, List fields) throws IOException {
File csvOutputFile = new File("storage/" + useCase.stringId + "_csv_file.csv")
FileWriter writer = new FileWriter(csvOutputFile)
workflowService.searchAll(QCase.case$.processIdentifier.eq(net)).eachWithIndex{ Case ca, int i ->
writer.write(i.toString() + ",")
fields.each {
if (ca.getFieldValue(it) != null) {
writer.write(escapeSpecialCharacters(ca.getFieldValue(it).toString()) + ",")
} else {
writer.write(",")
}
}
writer.write(System.lineSeparator())
}
return new FileFieldValue(csvOutputFile.name,csvOutputFile.path)
}
String escapeSpecialCharacters(String data) {
String escapedData = data.replaceAll("\\R", " ")
if (data.contains(",") || data.contains("\"") || data.contains("'")) {
data = data.replace("\"", "\"\"")
escapedData = "\"" + data + "\""
}
return escapedData
}