for loop issue
- September 12, 2018
- 2 replies
- 3843 views
Hi all,
could somebody show me what is wrong in my code?? I wanted to go thru all the rows in infotable to add them to stream. but unfortunately only last row is added, despite the fact that first part of code reads all *.csv file.
var params = {
path: "ptc.csv" /* STRING */,
columnMappings: undefined /* STRING */,
hasHeader: true /* BOOLEAN */,
longitudeField: undefined /* NUMBER */,
dateFormat: "dd.MM.yyyy HH:mm:ss" /* STRING */,
fileRepository: "HYDAC_FR" /* THINGNAME */,
latitudeField: undefined /* NUMBER */,
fieldDelimiter: undefined /* STRING */,
stringDelimiter: "\"" /* STRING */,
dataShape: "PTC_DATASHAPE" /* DATASHAPENAME */
};
var myInfoTable = Resources["CSVParserFunctions"].ReadCSVFile(params);
var tableLength = myInfoTable.rows.length;
for (var x = 0; x < tableLength; x++) {
var row = myInfoTable.rows[x];
var tags = new Array();
var timestamp = new Date();
var values = Things["PTC_STREAM"].CreateValues();
values.Par2 = row.Par2; //NUMBER
values.Par1 = row.Par1; //NUMBER
values.Par3 = row.Par3; //NUMBER
values.Date = row.Date; //DATETIME
var location = new Object();
location.latitude = 0;
location.longitude = 0;
location.elevation = 0;
location.units ="WGS84";
var params = {
tags : tags,
timestamp : timestamp,
source : me.name,
values : values,
location : location
};
Things["PTC_STREAM"].AddStreamEntry(params);
}
thx in advance
gucio

