Skip to main content
1-Visitor
January 10, 2018
Solved

Writing a value stream using the CSVParser extension

  • January 10, 2018
  • 10 replies
  • 6216 views

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);

Best answer by tyadav

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

22-Sapphire I
January 10, 2018

What are you getting in the csv output?

tyadav1-VisitorAuthor
1-Visitor
January 10, 2018

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

22-Sapphire I
January 10, 2018

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?