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

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

SOLVED

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(infoTableName:STRING("InfoTable"), dataShapeName:STRING):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 ? 

1 ACCEPTED SOLUTION

Accepted Solutions

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

Hi @Explorerhere29.

 

The service you are using will always overwrite.  Another approach:

 

Using ReadCSVFile, read in the existing CSV file in the repository as an Infotable as opposed to creating a new table each time as you are doing here:

 

dataShapeName:STRING):INFOTABLE(ds1)
var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

 

Once you're read in the CSV file as an Infotable, you can append rows as you are currently doing in your code.

 

Regards.

 

--Sharon

3 REPLIES 3

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

Hi @Explorerhere29.

 

The service you are using will always overwrite.  Another approach:

 

Using ReadCSVFile, read in the existing CSV file in the repository as an Infotable as opposed to creating a new table each time as you are doing here:

 

dataShapeName:STRING):INFOTABLE(ds1)
var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

 

Once you're read in the CSV file as an Infotable, you can append rows as you are currently doing in your code.

 

Regards.

 

--Sharon

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

For appending rows can I use WriteCSV function or some other ?

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

Thanks alot !!

This was the solution.