cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Setting a location field in an infotable

fblondy
7-Bedrock

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;

    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

4 REPLIES 4
billrei
12-Amethyst
(To:fblondy)

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?

fblondy
7-Bedrock
(To:billrei)

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;

    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);

}

paic
12-Amethyst
(To:fblondy)

Do you get a proper location when you do a logger.warn on your Things[row.to].geolocalisation?

billrei
12-Amethyst
(To:fblondy)

I suspect that what you are getting back from GetSubNetworkConnectionsWithTemplate() is an InfoTable of Java objects of Connection class. This would make the returned rows read only. I suggest that you build a new object and copy everything you want from the returned Connection classes like you are currently doing.

Announcements


Top Tags