Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
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
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?
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);
}
Do you get a proper location when you do a logger.warn on your Things[row.to].geolocalisation?
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.