Reading Plain Text Files

This example shows how to read data out of a CSV file which is controlled by Stages through a configuration management system.

1. Create a Report with a Stages Data Source and a Data Set

2. Create the following Data Set result columns:

NameType
NameString
ValueString

3. Copy the Data Set script from the example into your Data Set.

String.prototype.splitCSV = function(sep) {
 var regex = /(\s*'[^']+'|\s*[^,]+)(?=,|$)/g;
 return matches = this.match(regex);
}
var artifacts = stages.getCurrentProcess().getEntities("containsArtifact@SYSTEM");
for each (artifact in artifacts) {
 if (artifact.getProperty("DisplayName") == "Source Code") {
 var artifacts_instances =
 artifact.getEntities("containsInstance@SYSTEM");
 for each (artifacts_instance in artifacts_instances) {
 if (artifacts_instance.getProperty("LogicalName") ==
 "csv_example.csv") {
 is = artifacts_instance.getProperty("FileStream");
 dis = new BufferedReader(new InputStreamReader(is));
 while( ( rline=dis.readLine()) != null ) {
 var results = rline.splitCSV();
 dataset.setColumnValue("Name", results[0]);
 dataset.setColumnValue("Value", results[1]);
 dataset.storeResultRow();
 }
 }
 }
 }
}