# Dump Global contents to dashboard

**URL:** <https://discourse.nodered.org/t/dump-global-contents-to-dashboard/14639>\
**Category:** Dashboard\
**Created:** [22 August 2019 10:26 UTC](https://discourse.nodered.org/t/dump-global-contents-to-dashboard/14639 "2019-08-22T10:26:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SeRiusRod](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@SeRiusRod](https://discourse.nodered.org/u/SeRiusRod)\
**Post date:** [22 August 2019 10:26 UTC](https://discourse.nodered.org/t/dump-global-contents-to-dashboard/14639/1 "2019-08-22T10:26:27Z")

</div>

Hi, I'm trying to dump the contents of global object into a dashboard, but I'm not having success.  
In my node-red, I persist the values of my sensors per room in the global object, like:

global.rooms.living - temperature  
L hummidity  
L etc  
bathroom - temp  
L other...

What I want is to loop through the rooms printing it's name, and then all it's properties. The problem I have is that rooms name is variable and so the sensor data. I can't made them hard-coded in the template.  
Does anyone knows how to make this?

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [22 August 2019 10:47 UTC](https://discourse.nodered.org/t/dump-global-contents-to-dashboard/14639/2 "2019-08-22T10:47:11Z")

</div>

Heres a stackoverflow question that might set you going...

> <https://stackoverflow.com/questions/8085004/iterate-through-nested-javascript-objects>

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [22 August 2019 10:47 UTC](https://discourse.nodered.org/t/dump-global-contents-to-dashboard/14639/3 "2019-08-22T10:47:12Z")

</div>

You can use a change node, set msg.payload to jsonata with the global variable:  
`$globalContext("rooms")`

This will output an array with the names.

 ![45](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/32e9a568019f7a35b617b7ce16a233a5541f43a2.jpeg)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [22 August 2019 10:53 UTC](https://discourse.nodered.org/t/dump-global-contents-to-dashboard/14639/4 "2019-08-22T10:53:45Z")

</div>

Create the global as an object. Here is the idea

```auto
[{"id":"c242fa4f.e1aae","type":"inject","z":"985bfce.e485c","name":"Livingroom","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":100,"wires":[["676c3531.a8386c"]]},{"id":"dbd3a6b4.ceba","type":"inject","z":"985bfce.e485c","name":"Den","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":180,"wires":[["8154f67.6a65988"]]},{"id":"b86297b3.c5a81","type":"inject","z":"985bfce.e485c","name":"Kitchen","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":260,"wires":[["590311d9.096328"]]},{"id":"676c3531.a8386c","type":"change","z":"985bfce.e485c","name":"","rules":[{"t":"set","p":"house.livingroom","pt":"global","to":"{\"temperature\":67,\"humidity\":56}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":100,"wires":[[]]},{"id":"590311d9.096328","type":"change","z":"985bfce.e485c","name":"","rules":[{"t":"set","p":"house.kitchen","pt":"global","to":"{\"temperature\":84,\"humidity\":86}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":260,"wires":[[]]},{"id":"8154f67.6a65988","type":"change","z":"985bfce.e485c","name":"","rules":[{"t":"set","p":"house.den","pt":"global","to":"{\"temperature\":78,\"humidity\":51}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":180,"wires":[[]]}]

```

click on each and then go look at the context and you will see  
 ![23%20AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a490b1168b212676587334ebb5fe435813094888.png)

---

<div class="post-metadata">

**Author:** ![SeRiusRod](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@SeRiusRod](https://discourse.nodered.org/u/SeRiusRod)\
**Post date:** [22 August 2019 11:01 UTC](https://discourse.nodered.org/t/dump-global-contents-to-dashboard/14639/5 "2019-08-22T11:01:02Z")

</div>

@bakman2 @zenofmud Thanks for your answers. I did not explain myself so well. I already have the global.rooms object populated. I do it in other parts of my flows for every sensor. My problem is printing the global.rooms object content into a dashboard.  
Sorry for not explaining enough, I should have added the flow section:

```auto
[{"id":"c9a71c7d.055ca","type":"comment","z":"3bddddc6.ae5322","name":"Global output","info":"","x":110,"y":580,"wires":[]},{"id":"edfb10e4.c5c12","type":"inject","z":"3bddddc6.ae5322","name":"","topic":"","payload":"rooms","payloadType":"global","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":640,"wires":[["6174d9b3.acc278","1bcf428a.30278d"]]},{"id":"1bcf428a.30278d","type":"ui_template","z":"3bddddc6.ae5322","group":"8a8631eb.55035","name":"Rooms Output","order":1,"width":"6","height":"12","format":"<ul>\n <li ng-repeat=\"x in msg.payload\">\n <font color=\"red\">{{x.name}}</font> <!-- how to get the room name? -->\n <ul> <!-- don't want this to be hard-coded, want to iterate -->\n <li>{{x.temp}}</li>\n <li>{{x.hum}}</li>\n </ul>\n </li>\n</ul>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":460,"y":640,"wires":[[]]},{"id":"6174d9b3.acc278","type":"debug","z":"3bddddc6.ae5322","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":270,"y":620,"wires":[]},{"id":"8a8631eb.55035","type":"ui_group","z":"","name":"Global Dump","tab":"ffc494ce.ad9f28","disp":true,"width":"6","collapse":false},{"id":"ffc494ce.ad9f28","type":"ui_tab","z":"3bddddc6.ae5322","name":"Log","icon":"dashboard","order":4,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [22 August 2019 11:24 UTC](https://discourse.nodered.org/t/dump-global-contents-to-dashboard/14639/6 "2019-08-22T11:24:34Z")

</div>

Try this:

```auto
[{"id":"faa4a9f9.5b626","type":"ui_template","z":"50a9d0fb.ca78d","group":"a7708ea.3d20df","name":"Rooms Output","order":1,"width":"6","height":"12","format":"<ul>\n <li ng-repeat=\"(key, value) in msg.payload\">\n <font color=\"red\">{{key}}</font>\n <ul>\n <li>{{value.temperature}}</li>\n\n </ul>\n </li>\n</ul>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":556,"y":840,"wires":[[]]},{"id":"80bb6c9c.689268","type":"change","z":"50a9d0fb.ca78d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$globalContext(\"rooms\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":336,"y":812,"wires":[["e8f1bbfe.f80c4","faa4a9f9.5b626"]]},{"id":"e8f1bbfe.f80c4","type":"debug","z":"50a9d0fb.ca78d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":546,"y":784,"wires":[]},{"id":"1aebde81.b07921","type":"inject","z":"50a9d0fb.ca78d","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":144,"y":812,"wires":[["80bb6c9c.689268"]]},{"id":"a7708ea.3d20df","type":"ui_group","z":"","name":"Global Dump","tab":"22d42ec3.5ddd32","disp":true,"width":"6","collapse":false},{"id":"22d42ec3.5ddd32","type":"ui_tab","z":"50a9d0fb.ca78d","name":"Log","icon":"dashboard","order":4,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![SeRiusRod](https://avatars.discourse-cdn.com/v4/letter/s/278dde/32.png) [@SeRiusRod](https://discourse.nodered.org/u/SeRiusRod)\
**Post date:** [22 August 2019 11:56 UTC](https://discourse.nodered.org/t/dump-global-contents-to-dashboard/14639/7 "2019-08-22T11:56:19Z")

</div>

Thanks @bakman2, with a slight modification on your proposal I've got what I wanted:

```auto
<ul>
 <li ng-repeat="(key, value) in msg.payload">
 <font color="red">{{key}}</font>
    <ul>
        <li ng-repeat="(key, value) in value">
            {{key}} - {{value}}
        </li>
    </ul>
 </li>
</ul>

```

That dumps every property for each node.
