# Read SQL value and convert to Domoticz MQTT Topic - payload issue

**URL:** <https://discourse.nodered.org/t/read-sql-value-and-convert-to-domoticz-mqtt-topic-payload-issue/14504>\
**Category:** General\
**Created:** [19 August 2019 20:48 UTC](https://discourse.nodered.org/t/read-sql-value-and-convert-to-domoticz-mqtt-topic-payload-issue/14504 "2019-08-19T20:48:20Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 August 2019 19:18 UTC](https://discourse.nodered.org/t/read-sql-value-and-convert-to-domoticz-mqtt-topic-payload-issue/14504/21 "2019-08-22T19:18:19Z")

</div>

You deleted the incoming msg (overwrote it with empty object) THEN tried to access the values you had deleted.

If it's not obvious I'm afraid you're gonna struggle. Perhaps some basic JavaScript reading and learning would be your next stop.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [22 August 2019 19:19 UTC](https://discourse.nodered.org/t/read-sql-value-and-convert-to-domoticz-mqtt-topic-payload-issue/14504/22 "2019-08-22T19:19:24Z")

</div>

In essence, the very first line `msg = {};` destroyed the incoming data.

---

<div class="post-metadata">

**Author:** ![domotic](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/domotic/32/11084_2.png) [@domotic](https://discourse.nodered.org/u/domotic)\
**Post date:** [22 August 2019 19:25 UTC](https://discourse.nodered.org/t/read-sql-value-and-convert-to-domoticz-mqtt-topic-payload-issue/14504/23 "2019-08-22T19:25:36Z")

</div>

> [@Steve-Mcl](#):
>
> let result ={} result.idx=41; //set a property result.nvalue=0;//set a property restult.svalue=msg.payload[0].count\_e; // update existing msg.payload msg.payload = result; return msg;

Now I understand. Great explanation and education to me. Thank you Steve.  
The value is now in the string. The very last part is to get the value 4000 between '4000' for the Domoticz MQTT script.

_Update and closed for solved issue_:  
In my case the value 4000 from the SQL result is numeric. Domoticz expects for svalue a string. So in this example 4000 should be presented as ‘4000’.

To do this was relatively simple: use String(msg.payload[0].count\_e) and then it will work.

Many thanks to all who helped me to solve this issue. My Java knowledge is minor, no goal for me to become an expert, but thanks to the help of each other in this forum the boundary for many ‘users’ like me becomes smaller to explore the power of Node-Red.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [22 August 2019 20:50 UTC](https://discourse.nodered.org/t/read-sql-value-and-convert-to-domoticz-mqtt-topic-payload-issue/14504/24 "2019-08-22T20:50:21Z")

</div>

> [@Steve-Mcl](#):
>
> Wish I had some kind of automatic macro reply for the amount of times this comes up. Same with "I have 2 values from 2 nodes I need to add together..."

Not long ago there was some [discussion](https://discourse.nodered.org/t/template-for-how-to-share-code/12227) of a plugin for Discourse that can be used to create templates for replies like "how to share code", "what versions are you using?", and now these topics. I know the developers have better things to do than tinker with forum mechanics, but this feature, if used tactfully, could remove a minor irritant and help get new users more complete answers quickly.

---

<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:** [23 August 2019 01:07 UTC](https://discourse.nodered.org/t/read-sql-value-and-convert-to-domoticz-mqtt-topic-payload-issue/14504/25 "2019-08-23T01:07:19Z")

</div>

> [@Steve-Mcl](#):
>
> restult.svalue=msg.

restult.svalue is a typo it should be  
result.svalue

[Previous page](https://discourse.nodered.org/t/read-sql-value-and-convert-to-domoticz-mqtt-topic-payload-issue/14504.md?page=1)
