Skip to main content
1-Visitor
October 26, 2017
Question

Input date to refresh infotable

  • October 26, 2017
  • 1 reply
  • 2218 views

I have inserted two input date: startDate and endDate.

I have inserted this JS code in my service:

var params = {

    infoTableName : "InfoTable",

    dataShapeName : "TFPeopledata",

    startDate: startDate,

    endDate: endDate,

    maxItems: maxValues

};


var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

for each(var row in res.rows){

            var newEntry = new Object();

            newEntry.People_in_region = row.People_in_region;

            newEntry.date_trunc = dateAddHours(row.date_trunc, -2); // DATETIME

            result.AddRow(newEntry);

}

The prob is don''t refresh with date selected.

Screenshot-2017-10-26 ThingWorx Composer(1).png

    1 reply

    1-Visitor
    October 26, 2017

    I don't see the query, but anyway, your code duplicates entries ( as you are iterating over result collection variable and in the loop you are adding to the same result collection variable ). This is Javascript code not Java code I'm right?

    1-Visitor
    October 26, 2017

    I have used a ValueStream for data storage

    var res = Resources["CSVParserFunctions"].ReadCSVFile(params);

    var maxValues = 100;

    var oldFirst = false;

    if(startDate != undefined){

        maxValues = 5000;

    //    oldFirst = true;

    }

    var params = {

        oldestFirst: false /* BOOLEAN */,

        endDate: endDate /* DATETIME */,

        maxItems: maxValues /* NUMBER */,

        startDate: startDate /* DATETIME */

    };

    var history = me.QueryPropertyHistory(params);

    var result = history;

    var params = {

        infoTableName : "InfoTable",

        dataShapeName : "TFPeopledata",

        startDate: startDate,

        endDate: endDate,

        maxItems: maxValues

    };

    var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

    for each(var row in res.rows){

                var newEntry = new Object();

                newEntry.People_in_region = row.People_in_region;

                newEntry.date_trunc = dateAddHours(row.date_trunc, -2); // DATETIME

                result.AddRow(newEntry);

    }


    I got this as a result:
    Results

    timestamp

    I think the prob with the data stream.

    1-Visitor
    October 26, 2017

    I don't know man, your code doesn't have much sense I'm sorry.