# Crate an ARRAY in Function node to send it to G.Sheet Node

**URL:** https://discourse.nodered.org/t/crate-an-array-in-function-node-to-send-it-to-g-sheet-node/66984
**Category:** General
**Tags:** function-node
**Created:** [26 August 2022 18:32 UTC](https://discourse.nodered.org/t/crate-an-array-in-function-node-to-send-it-to-g-sheet-node/66984 "2022-08-26T18:32:44Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![lumanga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lumanga/32/58334_2.png) [@lumanga](https://discourse.nodered.org/u/lumanga)
#### Post date: [26 August 2022 18:32 UTC](https://discourse.nodered.org/t/crate-an-array-in-function-node-to-send-it-to-g-sheet-node/66984/1 "2022-08-26T18:32:44Z")

</div>

Dear All,  
I'm trying to solve thi issue but searching in the forum Topic, I'm not able to find a solution.

I want to add commands to this "function node" **to make an UNIQUE ARRAY that contains the 4 values PZEM** \*, to send to output 5 to send to google sheets.\*\*

(My G.Sheets Node works properly, forcing the array with an "Injection node"that send an array, the sheet is updated)

 ![array](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/6/4668b84f8f8d6b48aee0554c94ac0c703a43e60a.png)

So I neeed to make an only one ARRAY, sended once, with the 4 different PZEM varables created in this Fuunction node.

The ARRAY to be sended by G.Sheet Node, must be siple as : **["aaaa","bbb","ccc","ddd"]**

Here the Function Node where i need to make and add the output nr.5 "Datalogger":

```auto
let PEZMPower={}, PEZMYesterday={}, PEZMToday={}, PEZMTotal={}, X={}, Datalogger={};

PEZMPower.payload = msg.payload['ENERGY'].Power;
PEZMToday.payload = msg.payload['ENERGY'].Today;
PEZMYesterday.payload = msg.payload['ENERGY'].Yesterday;
PEZMTotal.payload = msg.payload['ENERGY'].Total;

return [PEZMPower, PEZMToday, PEZMYesterday, PEZMTotal, Datalogger];

```

Thanks in advance.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [26 August 2022 18:49 UTC](https://discourse.nodered.org/t/crate-an-array-in-function-node-to-send-it-to-g-sheet-node/66984/2 "2022-08-26T18:49:36Z")

</div>

Would this work for you?

```auto
let PEZMPower={}, PEZMYesterday={}, PEZMToday={}, PEZMTotal={}, X={}, Datalogger={};

PEZMPower.payload = msg.payload['ENERGY'].Power;
PEZMToday.payload = msg.payload['ENERGY'].Today;
PEZMYesterday.payload = msg.payload['ENERGY'].Yesterday;
PEZMTotal.payload = msg.payload['ENERGY'].Total;
Datalogger.payload = [
    msg.payload['ENERGY'].Power,
    msg.payload['ENERGY'].Today,
    msg.payload['ENERGY'].Yesterday,
    msg.payload['ENERGY'].Total
]

return [PEZMPower, PEZMToday, PEZMYesterday, PEZMTotal, Datalogger];

```

---

<div class="post-metadata">

### Author: ![lumanga](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lumanga/32/58334_2.png) [@lumanga](https://discourse.nodered.org/u/lumanga)
#### Post date: [26 August 2022 19:43 UTC](https://discourse.nodered.org/t/crate-an-array-in-function-node-to-send-it-to-g-sheet-node/66984/3 "2022-08-26T19:43:02Z")

</div>

Thank you very much... it WORKS, the ARRAY is correct made!!!

but the Gsheet node receive 2 or 3 inoput signal to write!!

 ![repeat](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/8597e7542be2cb5e6f3e6ed0a1a10cf45ad8bd89.png)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [26 August 2022 20:11 UTC](https://discourse.nodered.org/t/crate-an-array-in-function-node-to-send-it-to-g-sheet-node/66984/4 "2022-08-26T20:11:26Z")

</div>

I do not know yor set up, so at a guess.  
It looks like your mqtt node is outputting the same info twice 30 seconds apart.  
You could try setting it to output a string, then pass that through a filter/rbe node, so if output is the same string it will not pass, after the filter node you then can use a json node to convert the string to an JSON object.

Or look to see why the device is sending the data twice.

---

<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: [25 October 2022 20:12 UTC](https://discourse.nodered.org/t/crate-an-array-in-function-node-to-send-it-to-g-sheet-node/66984/5 "2022-10-25T20:12:04Z")

</div>

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