Skip to main content
1-Visitor
September 28, 2019
Solved

unable to open csv file using csvparser - ReadCSVFile from system repository

  • September 28, 2019
  • 1 reply
  • 3281 views

Hi , 

I am trying to read data from CSV using ReadCSVFile from CSV Parser Extension snippets.

I am getting below error while am trying to read data.

Error executing service importUserNames. Message :: Unable To Open [TestName.csv] in [SystemRepository] : Index: 2, Size: 2 car- See Script Error Log for more details.

 

Can someone help me in resolving this issues. 

 

Here is service code and attaching sample CSV am trying to upload.


var params = {
path: fileName /* STRING */,
columnMappings: 'Name;FullName;Password' /* STRING */,
hasHeader: true /* BOOLEAN */,
fileRepository: "SystemRepository" /* THINGNAME */,
fieldDelimiter: "," /* STRING */,
dataShape: "ImportUsers" /* DATASHAPENAME */
};

// result: INFOTABLE
var result = Resources["CSVParserFunctions"].ReadCSVFile(params);

for(var i=0;i<result.length;i++)
{
var params = {
password: result[i].Password /* STRING */,
name: result[i].Name /* STRING */,
description: result[i].FullName /* STRING */
};

// no return
Resources["EntityServices"].CreateUser(params);

};

 

 

Best answer by cmorfin

@polasaikrishna 

 

Can you open your csv file in a text editor and check that it is actually using a comma as delimiter.

 

This sample code works for me but I did get the same error when my csv was not formatted as expected.

If you still have issue, could you confirm the version of ThingWorx you are using and can you upload the actual csv file (not a screenshot of it)

 

Hope this helps

Christophe

 

1 reply

cmorfin19-TanzaniteAnswer
19-Tanzanite
September 30, 2019

@polasaikrishna 

 

Can you open your csv file in a text editor and check that it is actually using a comma as delimiter.

 

This sample code works for me but I did get the same error when my csv was not formatted as expected.

If you still have issue, could you confirm the version of ThingWorx you are using and can you upload the actual csv file (not a screenshot of it)

 

Hope this helps

Christophe

 

1-Visitor
September 30, 2019

Hi Christophe, 

 

Yes, My CSV file was corrupted and it worked with new CSV file.

 

19-Tanzanite
September 30, 2019

@polasaikrishna 

 

I am pleased to hear that the issue is fixed on your side.

In that case would it be possible for you to accept one of the answer as solution so that others can find more easily the solution to similar issue ?

 

Thank you

Kind regards

Christophe