# Just Not Working

**URL:** https://discourse.nodered.org/t/just-not-working/55327
**Category:** General
**Created:** [17 December 2021 03:38 UTC](https://discourse.nodered.org/t/just-not-working/55327 "2021-12-17T03:38:58Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![indedark](https://avatars.discourse-cdn.com/v4/letter/i/fbc32d/32.png) [@indedark](https://discourse.nodered.org/u/indedark)
#### Post date: [17 December 2021 03:38 UTC](https://discourse.nodered.org/t/just-not-working/55327/1 "2021-12-17T03:38:58Z")

</div>

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.

```auto
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;

```

 ![Flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7ac537abfb25ddb50d6772470fd370659a80041e.jpeg)

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?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [17 December 2021 09:43 UTC](https://discourse.nodered.org/t/just-not-working/55327/2 "2021-12-17T09:43:41Z")

</div>

> [@indedark](#):
>
> `var binDiamFile = global.get("BinDims["+binNo+"].payload.DiamFt","file");`

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?

---

<div class="post-metadata">

### Author: ![indedark](https://avatars.discourse-cdn.com/v4/letter/i/fbc32d/32.png) [@indedark](https://discourse.nodered.org/u/indedark)
#### Post date: [18 December 2021 18:49 UTC](https://discourse.nodered.org/t/just-not-working/55327/3 "2021-12-18T18:49:04Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![indedark](https://avatars.discourse-cdn.com/v4/letter/i/fbc32d/32.png) [@indedark](https://discourse.nodered.org/u/indedark)
#### Post date: [18 December 2021 19:19 UTC](https://discourse.nodered.org/t/just-not-working/55327/4 "2021-12-18T19:19:37Z")

</div>

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!

 ![Code](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/c/cc0013e665e62c2424e0a08f3ceb6e402bc699b7.jpeg)

Thanks a lot for your help @Colin !

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [1 January 2022 19:20 UTC](https://discourse.nodered.org/t/just-not-working/55327/5 "2022-01-01T19:20:17Z")

</div>

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