4 Replies Latest reply on Jun 19, 2015 9:53 AM by billrei RSS
    francky Explorer

    Setting a location field in an infotable

    Hello there !

    I've got a little problem here, I'm trying to get some network connections with the location field of the Things added in, but when I do this :

     

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

        var row = result.rows[x];

        row.location = Things[row.to].geolocalisation;

    }

     

    I only get some NaN in the field;

    I can still retrieve the field correctly when I add it in a new row (i'll probably just do this but I still wanted to ask).

     

    Thanks for reading

      • Re: Setting a location field in an infotable
        billrei Creator

        There are a few ways this snippet could fail.

         

        1. Are tableLength and result.rows the same length?

        2. Is row.to a valid ThingName that exists?

         

        You should add some logger.info(""); lines and look in your scripting log in Monitoring>Script to make sure these values are valid. NaN stands for Not A Number which is usually the result of an impossible calculation. Variables that fail to get assigned would would have the value, "undefined". Can you post the entire service?

          • Re: Setting a location field in an infotable
            francky Explorer

            Yeah, everything is looking good until i'm trying to put the location value in the location field

            as you'll see, row.to is a valid thingName since i'm getting it directly from the network  and the length are effectively one and the same

            and the geolocalisation field is a valid and legit one

             

            Here's the whole service (new working version) :

             

            var params = {

                maxDepth: depth /* NUMBER */,

                start: start /* STRING */

            };

            var nw = start ? Networks[network].GetSubNetworkConnectionsWithTemplate(params) : Networks[network].GetNetworkConnectionsWithTemplate(params);

             

            var params = {

                infoTableName : "InfoTable",

                dataShapeName : "NetworkConnectionWithData"

            };

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

             

            var tableLength = nw.rows.length;

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

                var row = nw.rows[x];

                var newEntry = new Object();

                newEntry.from = row.from; // STRING - isPrimaryKey = true

                // row.location =  Things[row.to].geolocalisation <-- This is what doesn't work

                newEntry.location = Things[row.to].geolocalisation; // LOCATION

                newEntry.avatar = Things[row.to].GetAvatarURL(); // IMAGELINK

                newEntry.thingTemplate = Things[row.to].thingTemplate; // THINGTEMPLATENAME

                newEntry.to = row.to; // STRING - isPrimaryKey = true

                newEntry.connectionType = row.connectionType; // STRING

                var dN = Things[row.to].displayName;

                newEntry.display = dN ? dN : row.to;

                newEntry.alert = Things[row.to].alert ? Things[row.to].alert : false;

                result.AddRow(newEntry);

            }