Grab Results from Different Node Into a Function

Hi experts,
I was wondering how I can merge different nodes into a Function, I know there is an element called Merge, but in my example I’d like to know how I can do it using a function, thus, perform filters by JS and make the function return something more customized.

Thanks

Hi @tuliovargas, from taking a quick look into this, your Function node MergeHTTP doesn’t seem to contain valid JavaScript.

For example, I am not familiar with the IF syntax used. Also the .map() method belongs to the Array class but runs against codes in $node["getPOSTCODE_API_A"].json["result"]["codes"].map(c => c.codes) (which seemed to be an Object rather than an array). So from looking at the example you have provided it’s unfortunately not clear to me what exactly you want to achieve here or which purpose the loop serves.

That said, the $node variable is available in Functions and you can use it to access results from different nodes. You could, for example verify this by simply running code like this in your Function node printing the first item:

console.log(JSON.stringify($node['getPOSTCODE_API_A'].json));
console.log(JSON.stringify($node['getPOSTCODE_API_B'].json));

You can then see the items for both nodes referenced above in your browser console:

In general, using console.log() is a good and simple way of just looking at the data of your Function (or Function Item) nodes, so my advice would be to use this a lot (especially when discovering unknown methods I tend to just console.log() my stuff immediately before and after to see what exactly a method might do).

I hope this gives you some pointers to get started. Let us know if you have any further queries.