# How to update a shared-status value from a function

**URL:** https://discourse.nodered.org/t/how-to-update-a-shared-status-value-from-a-function/62827
**Category:** General
**Tags:** http-request, function-node
**Created:** [19 May 2022 01:54 UTC](https://discourse.nodered.org/t/how-to-update-a-shared-status-value-from-a-function/62827 "2022-05-19T01:54:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Pabliski](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@Pabliski](https://discourse.nodered.org/u/Pabliski)
#### Post date: [19 May 2022 01:54 UTC](https://discourse.nodered.org/t/how-to-update-a-shared-status-value-from-a-function/62827/1 "2022-05-19T01:54:15Z")

</div>

Hello everyone - first time posting ...  
I am trying to update a shared-state value via function but I have not been successful.  
I have searched the forum and found similar questions, but not involving the shared status node.

I am trying to use the global.set function to do this ... here's a flow I've been playing with

```auto
[{"id":"8f4f9ea0.36e86","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"3196ed4f.f4ca22","type":"function","z":"8f4f9ea0.36e86","name":"Set global Test","func":"gn=msg.payload.split(\"/\")[1];\ngv=msg.topic;\n\nglobal.set('state.'+gn,gv);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":72,"wires":[[]]},{"id":"39f1edb.4533212","type":"inject","z":"8f4f9ea0.36e86","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"789","payload":"test/Test","payloadType":"str","x":130,"y":40,"wires":[["3196ed4f.f4ca22"]]},{"id":"36e85686.0c567a","type":"function","z":"8f4f9ea0.36e86","name":"Get global Test","func":"gn=msg.payload.split(\"/\")[1];\n\ngg=global.get('state.Test');\n\nmsg.val=gg;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":160,"wires":[["c81b2fe6.5e67e"]]},{"id":"c81b2fe6.5e67e","type":"debug","z":"8f4f9ea0.36e86","name":"f get","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":490,"y":160,"wires":[]},{"id":"5feb60bb.ab0df","type":"inject","z":"8f4f9ea0.36e86","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"test/Test","payloadType":"str","x":120,"y":160,"wires":[["36e85686.0c567a"]]},{"id":"425effcc.ad252","type":"inject","z":"8f4f9ea0.36e86","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"999","payload":"test/Test","payloadType":"str","x":130,"y":100,"wires":[["3196ed4f.f4ca22"]]},{"id":"2d1e4573.b89e2a","type":"set-shared-state","z":"8f4f9ea0.36e86","state":"68061c53.3d2934","name":"Test","triggerOnInit":true,"provideOutput":false,"outputs":0,"x":290,"y":240,"wires":[]},{"id":"87990c21.699c2","type":"inject","z":"8f4f9ea0.36e86","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"123","payloadType":"str","x":110,"y":220,"wires":[["2d1e4573.b89e2a"]]},{"id":"c29ce740.de4088","type":"get-shared-state","z":"8f4f9ea0.36e86","state":"68061c53.3d2934","name":"Test","triggerOnInit":true,"x":90,"y":320,"wires":[["43721755.93c128"]]},{"id":"43721755.93c128","type":"debug","z":"8f4f9ea0.36e86","name":"f state node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":310,"y":320,"wires":[]},{"id":"e9fb26e1.706728","type":"inject","z":"8f4f9ea0.36e86","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"456","payloadType":"str","x":110,"y":260,"wires":[["2d1e4573.b89e2a"]]},{"id":"90413802.6daef8","type":"function","z":"8f4f9ea0.36e86","name":"Get global Test","func":"gn=msg.payload.split(\"/\")[1];\n\ngg=global.get('State.Test');\n\nmsg.val=gg;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":400,"wires":[["75f10b41.a76f04"]]},{"id":"75f10b41.a76f04","type":"debug","z":"8f4f9ea0.36e86","name":"f get","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":470,"y":400,"wires":[]},{"id":"2e56c998.9eb956","type":"inject","z":"8f4f9ea0.36e86","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"test/Test","payloadType":"str","x":100,"y":400,"wires":[["90413802.6daef8"]]},{"id":"68061c53.3d2934","type":"shared-state","name":"Test","lbl":"","tags":"","historyCount":"2","dataType":"str","boolType":"bool","boolStrTrue":"","boolStrFalse":"","precision":"","numMin":"","numMax":"","unit":""}]

```

Thanks for looking.  
-Pabluski

---

<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: [18 July 2022 01:54 UTC](https://discourse.nodered.org/t/how-to-update-a-shared-status-value-from-a-function/62827/2 "2022-07-18T01:54:39Z")

</div>

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