Skip to main content
Jan 10, 2018 2:11 PM UTC
Solved

Writing a value stream using the CSVParser extension

Hi,

 

I am trying to generate a CSV file with all of the properties of the thing (stored in a valuestream).

 

I am using the example code for WriteCSV file given in PTC as a service in a thing and a CSV file is being generated with the headers from the DataShape. However, I am not getting the values for the respective properties in the CSV file. The code is as follows and I would like to know what changes are to be made (or a new example)  in order to populate the rows with the corresponding values from the value stream.

 

 

 

Thanks!

 

 

Best regards,

Tushar

 

 

 

 

var params = {

            infoTableName : "result",

            dataShapeName : "Test4_DataShape"

};

 

 

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(ds1)

var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

 

 

var newRow = new Object();

newRow.firstfield = "Speed";

newRow.secondfield = "Distance";

//infotable1Object.rows[0] = newRow;

result.AddRow(newRow);

 

 

  var params2 = {

  path: "test3.csv" /* STRING */,

  data: result /* INFOTABLE */,

  fileRepository: "SystemRepository" /* THINGNAME */,

  withHeader: true /* BOOLEAN */

  };

  // no return

  var result = Resources["CSVParserFunctions"].WriteCSVFile(params2);

tyadavAnswer
Jan 10, 2018 10:57 PM UTC

Hey Pai,

Thanks for the info. It works now. I passed the properties in the newObject() through result = Thing[ThingName].QueryPropertyHistory(newObject) before invoking the writeCSV service. The CSV file with all the property values is generated now.


Thanks!

10 replies

Jan 10, 2018 3:03 PM UTC

What are you getting in the csv output?

tyadavAuthor
Jan 10, 2018 3:05 PM UTC

Hey Pai Chung,

I am getting an empty csv file with the first row(headers) as the property values of the selected datashape. The code mentioned above has been directly taken from the support page of PTC for CSV Parser

Jan 10, 2018 7:17 PM UTC

When you comment out the last line and set the service output to InfoTable do you see the appropriate infotable being returned when running this service?