CSV Parser
* 
PTC support for ThingWorx’s CSV Parser extension ended, and the extension is no longer available for download from PTC’s download portal. PTC partner Free ThingWorx Widgets | IQNOX will provide support and future maintenance release for this extension. For more information, see PTC’s support article.
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
For more information on using the CSV Parser extension, see this article.
* 
It is recommended that import files are UTF-8 encoded.
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?