Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revisionBoth sides next revision
72:custom_reports_accessing_data_reading_plaintext [2019/02/27 18:26] – created ext-bkkr72:custom_reports_accessing_data_reading_plaintext [2019/10/04 07:01] cgl
Line 1: Line 1:
 ====== Reading Plain Text Files ====== ====== 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:
 +
 +^Name^Type|
 +|Name|String|
 +|Value|String|
 +
 +3. Copy the Data Set script from the example into your Data Set.
 +
 +<code>
 +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();
 + }
 + }
 + }
 + }
 +}
 +</code>
 +
 +\\