# Hello Again Help with array to dashboard

**URL:** <https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382>\
**Category:** Dashboard\
**Tags:** dashboard-2\
**Created:** [9 July 2024 21:13 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382 "2024-07-09T21:13:52Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![fogmajor](https://avatars.discourse-cdn.com/v4/letter/f/bbce88/32.png) [@fogmajor](https://discourse.nodered.org/u/fogmajor)\
**Post date:** [9 July 2024 21:13 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382/1 "2024-07-09T21:13:52Z")

</div>

I wonder if someone would be good enough to help me please  
I have a function that receives an array of 8 pieces of numeric data  
My function is as follows

```auto
for (var i = 0; i < msg.payload.length; i++) {
    var newMsg = {};
    newMsg.payload = msg.payload[i];
    node.send(newMsg);
}

```

return null;

there are 8 items in the array and on receiving the data i would like to assign each item of the array to 1 of 8 textboxes on a dashboard programmatically.

Thank you in anticipation

Andrew

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [9 July 2024 21:20 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382/2 "2024-07-09T21:20:06Z")

</div>

Well, quickly looking at it:

Could you post the actual payload that is received?

Because if it is not correctly structured it won't work.

(p.s.)

Is it you are receiving ONE message with the whole array, or EIGHT?

I am not sure because of how you worded the question.

---

<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:** [9 July 2024 21:21 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382/3 "2024-07-09T21:21:10Z")

</div>

You have 2 options

- add the payload element to each text node, e.g `{{msg.payload[0]}}` in the value format field, 0 to 7 .
- split the array with a split node and use the msg.parts.index in a switch node property field to send to each text node, using rule `== 0`. 0 to 7

~~p.s `node.send(newMsg)` or `return newMsg` should be outside the loop, you are sending the payload 8 time with varying elements, rather than once with 8 elements. Also `var neMsg = {}` should be before the loop.~~

[edit] Looking again the function is not even required. just use one of the options i suggested.

Example of option 1 with node-red-dashboard text nodes

```auto
[{"id":"d0da769320e30ab5","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1,2,3,4,5,6,7]","payloadType":"json","x":230,"y":40,"wires":[["77e8dca2af5bfa85","c769043b62334f2e"]]},{"id":"77e8dca2af5bfa85","type":"ui_text","z":"d1395164b4eec73e","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload[0]}}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":410,"y":40,"wires":[]},{"id":"c769043b62334f2e","type":"ui_text","z":"d1395164b4eec73e","group":"8b5cde76.edd58","order":5,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload[1]}}","layout":"row-spread","className":"","style":false,"font":"","fontSize":16,"color":"#000000","x":410,"y":80,"wires":[]},{"id":"8b5cde76.edd58","type":"ui_group","name":"default","tab":"8f03e639.85956","order":1,"disp":false,"width":"12","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

```

Example of option 2 with DB2 text nodes

```auto
[{"id":"d22816a2341152ef","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"one\",\"two\"]","payloadType":"json","x":454,"y":26.00000023841858,"wires":[["9c4556bbc7e2acac"]]},{"id":"9c4556bbc7e2acac","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":594,"y":26.00000023841858,"wires":[["7d5fb1326bcbdc61"]]},{"id":"7d5fb1326bcbdc61","type":"switch","z":"d1395164b4eec73e","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":714,"y":26.00000023841858,"wires":[["0e42041dcff44bb4","984e85a78eca56dc"],["9802e41f18e33d4e"]]},{"id":"0e42041dcff44bb4","type":"ui-text","z":"d1395164b4eec73e","group":"9d83cd8b3d5ee33c","order":1,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","style":false,"font":"","fontSize":16,"color":"#717171","className":"","x":874,"y":26.00000023841858,"wires":[]},{"id":"9802e41f18e33d4e","type":"ui-text","z":"d1395164b4eec73e","group":"9d83cd8b3d5ee33c","order":2,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","style":false,"font":"","fontSize":16,"color":"#717171","className":"","x":874,"y":66.00000023841858,"wires":[]},{"id":"984e85a78eca56dc","type":"debug","z":"d1395164b4eec73e","name":"debug 2562","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":714,"y":86.00000023841858,"wires":[]},{"id":"9d83cd8b3d5ee33c","type":"ui-group","name":"Group1","page":"c694d0ebe0d2b702","width":"6","height":"1","order":1,"showTitle":true,"className":"","visible":"true","disabled":"false"},{"id":"c694d0ebe0d2b702","type":"ui-page","name":"Page1","ui":"1805777f90e92057","path":"/page1","icon":"home","layout":"grid","theme":"a965ccfef139317a","order":2,"className":"","visible":"true","disabled":"false"},{"id":"1805777f90e92057","type":"ui-base","name":"dashboard","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":false},{"id":"a965ccfef139317a","type":"ui-theme","name":"HN Theme","colors":{"surface":"#5c5c5c","primary":"#00fdff","bgPage":"#383838","groupBg":"#4f4f4f","groupOutline":"#858585"},"sizes":{"pagePadding":"12px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"12px"}}]

```

_Option 2 would be more efficient as the array wo_uld not be cloned 7 times for each new wire.

---

<div class="post-metadata">

**Author:** ![fogmajor](https://avatars.discourse-cdn.com/v4/letter/f/bbce88/32.png) [@fogmajor](https://discourse.nodered.org/u/fogmajor)\
**Post date:** [10 July 2024 07:19 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382/4 "2024-07-10T07:19:38Z")

</div>

> [@fogmajor](#):
>
> ```auto
> for (var i = 0; i < msg.payload.length; i++) {
> var newMsg = {};
> newMsg.payload = msg.payload[i];
> node.send(newMsg);
> }
> 
> ```
> 
> return null;

Good Morning  
Please excuse my weak description, what i am trying to achieve is when my loop function iterates through the msg.payload[i];will get the first number array(0) and I want to assign that to txtbox0 on the dashboard, the second iteration would be array(1) and that value would be written to txtbox1.  
It would continue to array(7) and assign that to txtbox7.  
I guess the simple question is how do you programmatically assign a numeric value to a specific dashboard text box.

Thank you in advance  
andrew

---

<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:** [10 July 2024 08:58 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382/5 "2024-07-10T08:58:26Z")

</div>

There is no need for the function, you can feed your existing full message directly into all the text boxes. Then tell the text boxes what they should display by using the Value Format field. So in the first text box use `{{msg.payload[0]}}`  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6eab0bfad1678865e84d521e431cdb1157611972.png)  
In the second use `{{msg.payload[1]}}` and so on.

---

<div class="post-metadata">

**Author:** ![fogmajor](https://avatars.discourse-cdn.com/v4/letter/f/bbce88/32.png) [@fogmajor](https://discourse.nodered.org/u/fogmajor)\
**Post date:** [10 July 2024 12:26 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382/6 "2024-07-10T12:26:10Z")

</div>

> [@Colin](#):
>
> {{msg.payload[0]}}

Hi Colin  
thank you so much for helping me move forward, your suggestion makes perfect sense and I was over complicating it. I am using dashboard 2 and my text box does not have a setting for value.format.  
I have attached the properties i have along with how my array look.  
Thank you again.

Andrew

 ![nodered](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/0/e005718d15488ecb7fc4da18618ad6cfa0e08c4e.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:** [10 July 2024 13:30 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382/7 "2024-07-10T13:30:38Z")

</div>

I gave the exact same advise as @colin and provided examples. As stated it would use less resources if you split the payload and directed them via a switch node (example 2) as the payload array would not need to be cloned 7 time for each wire.

---

<div class="post-metadata">

**Author:** ![fogmajor](https://avatars.discourse-cdn.com/v4/letter/f/bbce88/32.png) [@fogmajor](https://discourse.nodered.org/u/fogmajor)\
**Post date:** [10 July 2024 13:52 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382/8 "2024-07-10T13:52:27Z")

</div>

E1cid yes you did thank you, As i was trying to explain i don't seem to have a format value box in the properties of my dashboard text box.  
I am an SQL programmer and nodered is new to me so you will have to excuse my ignorance.  
I am grateful for everyone's input and and would thank everyone when i resolve the issue

Kind regards  
Andrew

---

<div class="post-metadata">

**Author:** ![fogmajor](https://avatars.discourse-cdn.com/v4/letter/f/bbce88/32.png) [@fogmajor](https://discourse.nodered.org/u/fogmajor)\
**Post date:** [10 July 2024 13:53 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382/9 "2024-07-10T13:53:41Z")

</div>

In closing I imported your examples thank you but it threw an error unknown or missing ui-text?

---

<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:** [10 July 2024 14:06 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382/10 "2024-07-10T14:06:41Z")

</div>

You have not state which dashboard you are using.  
From the look of it it is DB2

delete the node that is throwing an error and delete any unused configs in the sidebar config tab.  
The add your text node to example 2, it should work for you.

[edit] Just tested this flow and works with DB2

```auto
[{"id":"d22816a2341152ef","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"one\",\"two\"]","payloadType":"json","x":454,"y":26.00000023841858,"wires":[["9c4556bbc7e2acac"]]},{"id":"9c4556bbc7e2acac","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":594,"y":26.00000023841858,"wires":[["7d5fb1326bcbdc61"]]},{"id":"7d5fb1326bcbdc61","type":"switch","z":"d1395164b4eec73e","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":714,"y":26.00000023841858,"wires":[["0e42041dcff44bb4","984e85a78eca56dc"],["9802e41f18e33d4e"]]},{"id":"0e42041dcff44bb4","type":"ui-text","z":"d1395164b4eec73e","group":"9d83cd8b3d5ee33c","order":1,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","style":false,"font":"","fontSize":16,"color":"#717171","className":"","x":874,"y":26.00000023841858,"wires":[]},{"id":"9802e41f18e33d4e","type":"ui-text","z":"d1395164b4eec73e","group":"9d83cd8b3d5ee33c","order":2,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","style":false,"font":"","fontSize":16,"color":"#717171","className":"","x":874,"y":66.00000023841858,"wires":[]},{"id":"984e85a78eca56dc","type":"debug","z":"d1395164b4eec73e","name":"debug 2562","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":714,"y":86.00000023841858,"wires":[]},{"id":"9d83cd8b3d5ee33c","type":"ui-group","name":"Group1","page":"c694d0ebe0d2b702","width":"6","height":"1","order":1,"showTitle":true,"className":"","visible":"true","disabled":"false"},{"id":"c694d0ebe0d2b702","type":"ui-page","name":"Page1","ui":"1805777f90e92057","path":"/page1","icon":"home","layout":"grid","theme":"a965ccfef139317a","order":2,"className":"","visible":"true","disabled":"false"},{"id":"1805777f90e92057","type":"ui-base","name":"dashboard","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":false},{"id":"a965ccfef139317a","type":"ui-theme","name":"HN Theme","colors":{"surface":"#5c5c5c","primary":"#00fdff","bgPage":"#383838","groupBg":"#4f4f4f","groupOutline":"#858585"},"sizes":{"pagePadding":"12px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"12px"}}]

```

~~Is there a bug here @joepavitt or am I doing something wrong.~~  
Never mind @joepavitt I forgot the split node (Doh)

---

<div class="post-metadata">

**Author:** ![fogmajor](https://avatars.discourse-cdn.com/v4/letter/f/bbce88/32.png) [@fogmajor](https://discourse.nodered.org/u/fogmajor)\
**Post date:** [10 July 2024 15:00 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382/11 "2024-07-10T15:00:59Z")

</div>

E1cid  
Your a super star, its in and working perfectly thank you

Regards  
Andrew

---

<div class="post-metadata">

**Author:** ![fogmajor](https://avatars.discourse-cdn.com/v4/letter/f/bbce88/32.png) [@fogmajor](https://discourse.nodered.org/u/fogmajor)\
**Post date:** [10 July 2024 15:01 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382/12 "2024-07-10T15:01:40Z")

</div>

Hi Colin  
Many thanks for your help in pointing me in the right direction, I am most grateful

Regards  
Andrew

---

<div class="post-metadata">

**Author:** ![fogmajor](https://avatars.discourse-cdn.com/v4/letter/f/bbce88/32.png) [@fogmajor](https://discourse.nodered.org/u/fogmajor)\
**Post date:** [10 July 2024 15:02 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382/13 "2024-07-10T15:02:05Z")

</div>

Thank you for your help

Regards  
Abdrew

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [11 July 2024 08:27 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382/14 "2024-07-11T08:27:14Z")

</div>

Glad to hear you got it working.

---

<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 July 2024 08:27 UTC](https://discourse.nodered.org/t/hello-again-help-with-array-to-dashboard/89382/15 "2024-07-25T08:27:50Z")

</div>

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