2 Replies Latest reply on Nov 11, 2017 9:42 AM by dsawyer RSS
    dsawyer Explorer

    create infotable from loop

    Hi All

     

    Please could I get some advise (probably fundamentals).

     

    I have the following code that I would like to display and send an email of an infotable as the result. How do I go about this?

     

    var CurrentTime = new Date();
    
    
    var sourceData = ThingTemplates["MeterTemplate"].GetImplementingThingsWithData();
    var tableLength = sourceData.rows.length;
    for (var x = 0; x < tableLength - 1; x++) {
        var currentRow = sourceData.rows[x];
        var sendfrom = "";
        
       
        
        
        var source = currentRow.name;
            if(CurrentTime.getTime() - Things[source].lastMeasureTime > 86400000) {
           logger.warn("Alert: (" + Things[source].name + ") hasnt recorded data since (" + Things[source].lastMeasureTime + ") ");
           }
    }
    
      • Re: create infotable from loop
        Adam Macierzyński Explorer

        Hi Darryl,

         

        Can you tell us where the problem is? Are you receiving any errors? If so, where exactly?

         

        Btw. I noticed standard looping issue in your code. It should look like this:

        for(var x=0; x < tableLength; x++)
        

        or

        for(var x=0; x <= tableLength -1; x++)
        

         

        Otherwise you will lose your last record, while iterating through infotable.

         

        Regards,

        Adam