Skip to main content
1-Visitor
March 22, 2016
Solved

CSV Parser Help

  • March 22, 2016
  • 3 replies
  • 19106 views

So, I am running 6.0 and am trying to parse a CSV file.  I have downloaded the CSV Parser Extension and have boiled down the code to the bare minimum and haven't been able to get it to work.

In fact, I have a very simple test and my results are the same as when I use the GetCSVFile Method.  Here below I am using a very simple example and the result is that I only get the very first column and not the second column. I am certain I am doing something wrong but I haven't been able to locate the documentation for the extension.  I have looked through the forum and found links but they are dead links. 

Can someone help with getting the Description column populated?

Thanks in advance

var params = {

  columnMappings: "Tagname; Description;" /* STRING */,

  hasHeader: "false" /* BOOLEAN */,

  longitudeField: undefined /* NUMBER */,

  dateFormat: undefined /* STRING */,

  latitudeField: undefined /* NUMBER */,

  fieldDelimiter: undefined /* STRING */,

  stringDelimiter: undefined /* STRING */,

  content: '"XV101,Valve Input"' /* STRING */,

  dataShape: "PES_Tags" /* DATASHAPENAME */

};

// result: INFOTABLE

var result = Resources["CSVParserFunctions"].ParseCSVFile(params);

Best answer by CarlesColl

Few things that may cause it:

  • ColumnMappings
    • Remove spaces between columns ( you have a space after the ";" )
    • Remove the last ";"
  • hasHeader
    • change "true" for true
  • FieldDelimiter
    • ","
  • StringDelimiter
    • "\""
  • content
    • I've never parsed a string content, I parse csv files from file repositories
    • But on your case, you are opening and closing a " on your content, you should not, at least for all the row, you can for every String column
    • When you parse CSV files you need a blank line at the end, maybe it's the case with content, then you will need to add at the end \n
  • dataShape, it should exist.

3 replies

1-Visitor
March 22, 2016

Few things that may cause it:

  • ColumnMappings
    • Remove spaces between columns ( you have a space after the ";" )
    • Remove the last ";"
  • hasHeader
    • change "true" for true
  • FieldDelimiter
    • ","
  • StringDelimiter
    • "\""
  • content
    • I've never parsed a string content, I parse csv files from file repositories
    • But on your case, you are opening and closing a " on your content, you should not, at least for all the row, you can for every String column
    • When you parse CSV files you need a blank line at the end, maybe it's the case with content, then you will need to add at the end \n
  • dataShape, it should exist.
17-Peridot
March 21, 2018

Hi.

If i am having a column which data type is date time means, how to parse in thingworx? 

14-Alexandrite
March 23, 2016

Hi Jeff,

Here is an example per the test data you provided and it works on my Thingworx 7.0.0-b479:

var params = {

    columnMappings: "Tagname;Description" /* STRING */,

    hasHeader: "false" /* BOOLEAN */,

    longitudeField: undefined /* NUMBER */,

    dateFormat: undefined /* STRING */,

    latitudeField: undefined /* NUMBER */,

    fieldDelimiter: "," /* STRING */,

    stringDelimiter: "\"" /* STRING */,

    content: "XV101,Valve Input\n" /* STRING */,

    dataShape: "PES_Tags" /* DATASHAPENAME */

};

// result: INFOTABLE

var result = Resources["CSVParserFunctions"].ParseCSVFile(params);

Hope this helps,

Thanks,

Br,

Anna

jeffm1-VisitorAuthor
1-Visitor
March 25, 2016

Thanks both of you!!!! My issue was the space between the columnMappings... I appreciate it.