CSV Parser
A comma-separated values (CSV) file stores tabular data (numbers and text) in plain-text form. With the ThingWorx CSV Parser extension, parse and manipulate CSV files within ThingWorx. This allows you to import CSV data and store in ThingWorx, or merely treat it as a data store and extract additional value from the CSV data. To use the CSV Parser extension, download and import the CSVParser_Extensions.zip into ThingWorx. The package imports the following into ThingWorx:
CSVParserFunctions Resource
* 
It is recommended that import files are UTF-8 encoded.
* 
The CSV Parser extension is available on support.ptc.com under Download Software > Order or Download Software Updates > ThingWorx Foundation > Release <latest version> > ThingWorx CSV Parser > Most Recent Datecode > CSV-Parser-Extensions.
Services
The CSV Parser functionality is located in the services Snippets tab with the following services:
GetCSVFile: This service parses a CSV file from an HTTP GET (output result is an infotable). It has the following configurable parameters:
header (Http headers)
fieldDelimiter (field delimiter)
ignoreSSLErrors (Ignore SSL certification errors)
columnMappings (Column maps)
hasHeader (CSV file has a header row)
latitudeField (Latitude field index)
password (URL password)
url (URL)
longitudeField (Longitude field index)
username (URL username)
stringDelimiter (string value delimiter)
dateFormat (Date time format)
dataShape (Data shape)
timeout (Optional timeout in seconds)
GetOrderedFieldOutput: This service returns a list of data exports (output result is an infotable). It has the following configurable parameters:
orderedFieldList (the infotable to use as the source)
inputInfotable (an ordered CSV list of the fields to be returned from the input table)
ParseCSVFile:
This service parses a CSV file from text (the output result is an infotable). It has the following configurable parameters:
content (Content)
fieldDelimiter (Field delimiter)
columnMappings (Column maps)
hasHeader (File has header row)
latitudeField (Latitude field index)
longitudeField (Longitude field index)
stringDelimiter (String value delimiter)
dateFormat (Date time format)
dataShape (Data shape)
ReadCSVFile: This service parses a CSV file from a repository (the output result is an infotable). It has the following configurable parameters:
path (Path to file)
fieldDelimiter (Field delimiter)
columnMappings (Column maps)
hasHeader (File has a header row)
latitudeField (Latitude field index)
longitudeField (Longitude field index)
stringDelimiter (String value delimiter)
dateFormat (Date time format)
dataShape (Data shape)
WriteCSVFile: This service writes a CSV file to a repository. It has the following configurable parameters:
data (Infotable data)
path (Path to file)
fileRepository (File repository name)
withHeader (Use headers for column names)
Example: ReadCSV
In the following example, the Data Shape is defined as ds1 with two string fields.
var params = {
path: "test5.csv" /* STRING */,
columnMappings: undefined /* STRING */,
hasHeader: undefined /* BOOLEAN */,
longitudeField: undefined /* NUMBER */,
dateFormat: undefined /* STRING */,
fileRepository: "SystemRepository" /* THINGNAME */,
latitudeField: undefined /* NUMBER */,
fieldDelimiter: undefined /* STRING */,
stringDelimiter: undefined /* STRING */,
dataShape: "ds1" /* DATASHAPENAME */
};


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

var params = {
infoTableName : "InfoTable",
dataShapeName : "ds1"
};

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

var newRow = new Object();
newRow.firstfield = "FirstFieldValue";
newRow.secondfield = "SecondFieldValue";
//infotable1Object.rows[0] = newRow;
result.AddRow(newRow);

var params2 = {
path: "test4.csv" /* STRING */,
data: result /* INFOTABLE */,
fileRepository: "SystemRepository" /* THINGNAME */,
withHeader: undefined /* BOOLEAN */
};
// no return
var result = Resources["CSVParserFunctions"].WriteCSVFile(params2);
Was this helpful?