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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

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

Explorerhere29
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(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 ? 

ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

3 REPLIES 3

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

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

Thanks alot !!

This was the solution.

Announcements


Top Tags