cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

How to append a CSV file in repository(WriteCSV) using CSV Parser function in ThingWorx ?

Explorer
7-Bedrock

How to append a CSV file in repository(WriteCSV) using CSV Parser function in ThingWorx ?

I'm trying append the csv file in the repository with a service.

My code looks like below.

var params = {
infoTableName : "result",
dataShapeName : "WriteDataShape"
};

// CreateInfoTableFromDataShape(infoTableNameSmiley FrustratedTRING("InfoTable"), dataShapeNameSmiley FrustratedTRING):INFOTABLE(ds1)
var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
var newRow = new Object();
newRow.ID = ID;
newRow.Name = Name;
//infotable1Object.rows[0] = newRow;
result.AddRow(newRow);
var params2 = {
path: "WriteFile.CSV" /* STRING */,
data: result /* INFOTABLE */,
fileRepository: "SystemRepository" /* THINGNAME */,
withHeader: true /* BOOLEAN */
};
// no return
var result = Resources["CSVParserFunctions"].WriteCSVFile(params2);

Could anyone please tell me why the data in CSV file gets overwritten every time I call this service ?

2 REPLIES 2

CSV write extension it's not designed to append to the file, if you want to append, you will have to read first and the rewrite the whole file, but of course this won't be super efficient. Otherwise you may need to build your own extension ( or you may try with WriteToTextFile service that exists on FileRepository things which I think it allows to append content ).

Hi,

 

Since i'm new to thingworx, could you kindly help me by providing some example here?

 

Thank you!!

Announcements


Top Tags