# Displaying Boolean Global Via a Switch Node

**URL:** <https://discourse.nodered.org/t/displaying-boolean-global-via-a-switch-node/41584>\
**Category:** Dashboard\
**Created:** [24 February 2021 19:43 UTC](https://discourse.nodered.org/t/displaying-boolean-global-via-a-switch-node/41584 "2021-02-24T19:43:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gcortes](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gcortes/32/37823_2.png) [@gcortes](https://discourse.nodered.org/u/gcortes)\
**Post date:** [24 February 2021 19:43 UTC](https://discourse.nodered.org/t/displaying-boolean-global-via-a-switch-node/41584/1 "2021-02-24T19:43:02Z")

</div>

I've created a global variable and set it to boolean true or false in my sequences. I would like to display it on a dashboard. I connected the change nodes for the global to a switch and set on and off payload to global. and then entered the global variable name into the input field next to it. The switch doesn't change. It seems as something is missing or I'm not understanding how it works. Is the switch just testing for the existence of the variable and not its setting? If it's the setting, how do I indicate true or false? I tried global.varName, varName, varNane.true, and global.varName.true.

If there is documentation on this somewhere, I'll gladly refer to it. My Internet searches didn't turn anything up.

Related nodes for a text node (wrong one, but answered by @Paul-Reed)

```auto
[{"id":"a4cbbbc3.55b9d8","type":"change","z":"4ed8298c.44ba6","name":"Set Hallway Occupied","rules":[{"t":"set","p":"hallwayOccupied","pt":"global","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":100,"wires":[["bf55f2c9.225a48","689fb39c.d7e034","eb6b6af0.e39438"]]},{"id":"69cc6d5f.effd5c","type":"change","z":"4ed8298c.44ba6","name":"Reset Hallway Occupied","rules":[{"t":"set","p":"hallwayOccupied","pt":"global","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":120,"wires":[["689fb39c.d7e034","eb6b6af0.e39438"]]},{"id":"eb6b6af0.e39438","type":"ui_text","z":"4ed8298c.44ba6","group":"d127657e.88b01","order":1,"width":0,"height":0,"name":"","label":"Hallway Occupied:","format":"{{global.hallwayOccupied | char}}","layout":"row-spread","x":1480,"y":60,"wires":[]},{"id":"d127657e.88b01","type":"ui_group","name":"Group 3","tab":"5a31f675.ba7d2","order":3,"disp":true,"width":6},{"id":"5a31f675.ba7d2","type":"ui_tab","name":"Test Tab","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

## Update

I originally posted the wrong sequence. It's for using a text node, which @Paul-Reed answered. My question was about the switch node. Here is the correct example:

```auto
[{"id":"a4cbbbc3.55b9d8","type":"change","z":"4ed8298c.44ba6","name":"Set Hallway Occupied","rules":[{"t":"set","p":"hallwayOccupied","pt":"global","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":140,"wires":[["bf55f2c9.225a48","689fb39c.d7e034","4efd4b20.9ef094"]]},{"id":"69cc6d5f.effd5c","type":"change","z":"4ed8298c.44ba6","name":"Reset Hallway Occupied","rules":[{"t":"set","p":"hallwayOccupied","pt":"global","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1170,"y":160,"wires":[["689fb39c.d7e034","4efd4b20.9ef094"]]},{"id":"689fb39c.d7e034","type":"ui_switch","z":"4ed8298c.44ba6","name":"Hallway Occupied Global","label":"Hallway Occupied Global","tooltip":"","group":"d127657e.88b01","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"global.hallwayOccupied","onvalueType":"global","onicon":"","oncolor":"","offvalue":"global.hallwayOccupied","offvalueType":"global","officon":"","offcolor":"","animate":false,"x":1550,"y":240,"wires":[[]]},{"id":"d127657e.88b01","type":"ui_group","name":"Group 3","tab":"5a31f675.ba7d2","order":3,"disp":true,"width":6},{"id":"5a31f675.ba7d2","type":"ui_tab","name":"Test Tab","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [24 February 2021 20:03 UTC](https://discourse.nodered.org/t/displaying-boolean-global-via-a-switch-node/41584/2 "2021-02-24T20:03:36Z")

</div>

Hi Curt, welcome to the forum.  
Is it possible that you could [export the flow](https://nodered.org/docs/user-guide/editor/workspace/import-export) which you are having problems with, and paste it here in the forum.  
Just try to include the nodes which are necessary to demonstrate the problem.

Before doing so, please read this post about how to share flows in the forum, otherwise we will not be able to import it.

> [@How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506):
>
> To share code samples or flow json in this forum, you need to take care to format it properly so that it is displayed correctly. The easiest way to do that is to click the 'Preformatted Text' button in the toolbar: [image] Then paste in your code or flow json. You should end up with three back-tick characters - ``` - on their own line before and after the code. On standard US English keyboards, this is on the same key as the ~ character. Using the backticks will ens…

---

<div class="post-metadata">

**Author:** ![gcortes](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gcortes/32/37823_2.png) [@gcortes](https://discourse.nodered.org/u/gcortes)\
**Post date:** [24 February 2021 20:14 UTC](https://discourse.nodered.org/t/displaying-boolean-global-via-a-switch-node/41584/3 "2021-02-24T20:14:58Z")

</div>

@Paul-Reed No problem. Added to the original post

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [24 February 2021 20:28 UTC](https://discourse.nodered.org/t/displaying-boolean-global-via-a-switch-node/41584/4 "2021-02-24T20:28:52Z")

</div>

The 2 change nodes in your flow only change the value stored in global context.  
But to change the value in the text node, you must retrieve the value from global context, and inject it into the text node - take a look at the flow below.

```auto
[{"id":"a4cbbbc3.55b9d8","type":"change","z":"a4801683.1c0448","name":"Set Hallway Occupied","rules":[{"t":"set","p":"hallwayOccupied","pt":"global","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":3030,"wires":[[]]},{"id":"69cc6d5f.effd5c","type":"change","z":"a4801683.1c0448","name":"Reset Hallway Occupied","rules":[{"t":"set","p":"hallwayOccupied","pt":"global","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":3070,"wires":[[]]},{"id":"eb6b6af0.e39438","type":"ui_text","z":"a4801683.1c0448","group":"61d2dced.3db8f4","order":1,"width":"4","height":"1","name":"","label":"Hallway Occupied:","format":"{{msg.payload}}","layout":"row-spread","x":500,"y":3150,"wires":[]},{"id":"cc7666d0.b64df8","type":"inject","z":"a4801683.1c0448","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":100,"y":3030,"wires":[["a4cbbbc3.55b9d8"]]},{"id":"b2520f05.7a9df","type":"inject","z":"a4801683.1c0448","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":100,"y":3070,"wires":[["69cc6d5f.effd5c"]]},{"id":"87e1a926.1377f8","type":"change","z":"a4801683.1c0448","name":"Get global state","rules":[{"t":"set","p":"payload","pt":"msg","to":"hallwayOccupied","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":3150,"wires":[["eb6b6af0.e39438"]]},{"id":"1ef8a44f.7c779c","type":"inject","z":"a4801683.1c0448","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":100,"y":3150,"wires":[["87e1a926.1377f8"]]},{"id":"61d2dced.3db8f4","type":"ui_group","name":"flowtest","tab":"3c94630c.13381c","order":1,"disp":true,"width":16,"collapse":false},{"id":"3c94630c.13381c","type":"ui_tab","name":"Test","icon":"dashboard","order":9}]

```

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [24 February 2021 20:48 UTC](https://discourse.nodered.org/t/displaying-boolean-global-via-a-switch-node/41584/5 "2021-02-24T20:48:49Z")

</div>

I would suggest that you reconfigure your flow so that the Boolean value directly changes the 'text node' text, and also saves the value to context.  
You may only need to retrieve and inject the context value into the text node if you reboot, restart the flow, etc.

Example

```auto
[{"id":"a4cbbbc3.55b9d8","type":"change","z":"a4801683.1c0448","name":"Set Hallway Occupied","rules":[{"t":"set","p":"hallwayOccupied","pt":"global","to":"true","tot":"bool"},{"t":"set","p":"payload","pt":"msg","to":"true","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":3030,"wires":[["eb6b6af0.e39438"]]},{"id":"69cc6d5f.effd5c","type":"change","z":"a4801683.1c0448","name":"Reset Hallway Occupied","rules":[{"t":"set","p":"hallwayOccupied","pt":"global","to":"false","tot":"bool"},{"t":"set","p":"payload","pt":"msg","to":"false","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":3070,"wires":[["eb6b6af0.e39438"]]},{"id":"eb6b6af0.e39438","type":"ui_text","z":"a4801683.1c0448","group":"61d2dced.3db8f4","order":1,"width":"4","height":"1","name":"","label":"Hallway Occupied:","format":"{{msg.payload}}","layout":"row-spread","x":600,"y":3040,"wires":[]},{"id":"cc7666d0.b64df8","type":"inject","z":"a4801683.1c0448","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":100,"y":3030,"wires":[["a4cbbbc3.55b9d8"]]},{"id":"b2520f05.7a9df","type":"inject","z":"a4801683.1c0448","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":100,"y":3070,"wires":[["69cc6d5f.effd5c"]]},{"id":"87e1a926.1377f8","type":"change","z":"a4801683.1c0448","name":"Get global state","rules":[{"t":"set","p":"payload","pt":"msg","to":"hallwayOccupied","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":3130,"wires":[["eb6b6af0.e39438"]]},{"id":"1ef8a44f.7c779c","type":"inject","z":"a4801683.1c0448","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":170,"y":3130,"wires":[["87e1a926.1377f8"]]},{"id":"61d2dced.3db8f4","type":"ui_group","name":"flowtest","tab":"3c94630c.13381c","order":1,"disp":true,"width":16,"collapse":false},{"id":"3c94630c.13381c","type":"ui_tab","name":"Test","icon":"dashboard","order":9}]

```

---

<div class="post-metadata">

**Author:** ![gcortes](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gcortes/32/37823_2.png) [@gcortes](https://discourse.nodered.org/u/gcortes)\
**Post date:** [24 February 2021 20:50 UTC](https://discourse.nodered.org/t/displaying-boolean-global-via-a-switch-node/41584/6 "2021-02-24T20:50:30Z")

</div>

You example fixes my problem, but not the one I wanted to ask. I posted the wrong sequence. Nonetheless. I needed an answer for the text node as well, so thanks. Is it the case that the value field will only accept payload data? Given that it's freeform, I was hoping I could use {{ global.hallwayOccupied }}

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [24 February 2021 20:57 UTC](https://discourse.nodered.org/t/displaying-boolean-global-via-a-switch-node/41584/7 "2021-02-24T20:57:54Z")

</div>

> [@gcortes](#):
>
> I was hoping I could use {{ global.hallwayOccupied }}

No you can't do that, you can change the source of the incoming msg to for example `{{msg.hallway}}` or use HTML or angular filters (which change the way the text is displayed - but not the msg source).  
The text to be displayed needs to flow into the text node. The text node will not just go and get it (if that makes sense!)

---

<div class="post-metadata">

**Author:** ![gcortes](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gcortes/32/37823_2.png) [@gcortes](https://discourse.nodered.org/u/gcortes)\
**Post date:** [24 February 2021 21:16 UTC](https://discourse.nodered.org/t/displaying-boolean-global-via-a-switch-node/41584/8 "2021-02-24T21:16:19Z")

</div>

> [@Paul-Reed](#):
>
> No you can't do that, you can change the source of the incoming msg to for example `{{msg.hallway}}` or use HTML or angular filters (which change the way the text is displayed - but not the msg source).

That makes sense. I was trying to make it do more than it is supposed to.

I also fed text into the switch node and got it to work. You would think that, since you and set to the on and off payload to global, you could use global data.

---

<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:** [10 March 2021 21:16 UTC](https://discourse.nodered.org/t/displaying-boolean-global-via-a-switch-node/41584/9 "2021-03-10T21:16:53Z")

</div>

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