Just Not Working

Have the following code in a function node. Function node fed by a join node that's fed with a Drop Down select and a table.

I'm looking for table values that are undefined or null so that I can use a previously entered value so user doesn't have to re-enter unchanging variables. However, it just doesn't work. I don't get an error out of the function node. The function node doesn't seem to be processing the global.get("var["+element_number+"].payload.variable. That being said, I'm trying to assign an incoming payload to the element number variable.

var binNo = msg.payload.Bin;
var binDiam = msg.payload.BinDims.DiamFt;
var binRings = msg.payload.BinDims.Rings;
var binRingHeight = msg.payload.BinDims.RingHeightIn;
var binFloorGap = msg.payload.BinDims.FloorGap;
var binDiamFile = global.get("BinDims["+binNo+"].payload.DiamFt","file");
var binRingsFile = global.get("BinDims["+binNo+"].payload.Rings","file");
var binRingHeightFile = global.get("BinDims["+binNo+"].payload.RingHeightIn","file");
var binFloorGapFile = global.get("BinDims["+binNo+"].payload.FloorGap","file");

var PI = 3.1415926535;
var binBushels = 0;
var binRHFeet = 0;
var binFGFeet = 0;
var binHeightToEave = 0;
var binConeVolume = 0;

var msg1 = {};

if (typeof binDiam === 'undefined' || binDiam === null){
    binDiam = binDiamFile;
}

if (typeof binRings === 'undefined' || binDiam === null){
    binRings = binRingsFile;
}

if (typeof binRingHeight === 'undefined' || binDiam === null){
    binRingHeight = binRingHeightFile;
}

if (typeof binFloorGap === 'undefined' || binDiam === null){
    binFloorGap = binFloorGapFile;
}

binRHFeet = binRingHeight / 12;
binFGFeet = binFloorGap / 12;
binHeightToEave = ((binRHFeet * binRings) - binFGFeet);

binBushels = ((PI*(binDiam/2)*(binDiam/2))*binHeightToEave);
binConeVolume = PI * (binDiam/2) * (binDiam/2) *((0.4244748162*(binDiam/2))/3);
binBushels = binBushels+binConeVolume;
binBushels = binBushels * 0.7783750000;

binBushels = Math.round(binBushels*1)/1;

msg1.payload = {DiamFt:binDiam, Rings:binRings,
 RingHeightIn:binRingHeight, FloorGap:binFloorGap, CalcVolume:binBushels};


    global.set("BinDim["+binNo+"]",msg1,"file");

return msg1;

The point of this flow to allow user to update any changing parameters, re-calculate the pertinent values and refresh the tab. When I enter data into ALL of the fields in the table, it functions properly.

Any suggestions?

I always try to avoid fetching items from within structures in global. It can be made to work but I find it too confusing.
I would do something like
let binDims = global.get("BinDims", "file")
Then you should be able to do
let binDiamFile = binDims[binNo].payload.DiamFt","file");
and at the end
global.set("BinDims", binDims, "file")

Is this an error in your code?
global.set("BinDim["+binNo+"]",msg1,"file");
Should that be "BinDims", or is that a different object?

Nice catch on the typo... maybe that's why it wasn't working!!!

I'll test this out later tonight and report back.

I will say that I like that solution... very elegant and functional. I appreciate your feedback!

Your suggestion fixed my problem and works like a charm...

I just need to remember to help myself and look for typos as well! Copy and paste works well, just need to change ALL of the variables!

Thanks a lot for your help @Colin !

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.