# How using msg.topic, payload and transcription in compare data in switch node

**URL:** <https://discourse.nodered.org/t/how-using-msg-topic-payload-and-transcription-in-compare-data-in-switch-node/25365>\
**Category:** General\
**Created:** [23 April 2020 14:38 UTC](https://discourse.nodered.org/t/how-using-msg-topic-payload-and-transcription-in-compare-data-in-switch-node/25365 "2020-04-23T14:38:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lingzhongli](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lingzhongli/32/20078_2.png) [@lingzhongli](https://discourse.nodered.org/u/lingzhongli)\
**Post date:** [23 April 2020 14:38 UTC](https://discourse.nodered.org/t/how-using-msg-topic-payload-and-transcription-in-compare-data-in-switch-node/25365/1 "2020-04-23T14:38:23Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/58698a629efe6d5fe125b022984e7e8ea0f18a61.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/4/d4d2a3e8f87a0bff17756a1e6ba475abf33aadf6.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/4/8478d352c9966b4c480762fa52b7b97c9a5bde62.png)

i am doing my project that are using voice to open the door... so, i need to comapre the voice from microphone and comapre the voice data in database....if same the the it will upload the name data from user table to history table and it have output sound "welcome" , if not same the just output sound sound "access denied" only

so, nowi have problem from the about the message...i very confuse...i don't know i have using correct `msg.` in compare both data in ` compare data node` (switch node)...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/c/fc12e75c21859a9daa340fb97348a2daef8bbd9c.png)

**And below is the code in**

`read voice data` node

```auto
msg.topic = "SELECT VOICE FROM USER";
return msg; 

```

`upload name data` node ( **have error** )

```auto
msg.voice = msg.payload;
msg.name = msg.transcription;
//msg.transcription = "SELECT NAME FROM USER WHERE VOICE = msg.name;” 
msg.topic= "INSERT INTO HISTORY (NAME) VALUES( "+ msg.voice+ ");"
return msg;

```

**Below is the complete flow**

```auto
[{"id":"ee60c3e3.69e03","type":"mysql","z":"98f4cc17.965b","mydb":"7c738c44.e9a364","name":"DB_MYSQL","x":470,"y":100,"wires":[["df7c1555.276f08"]]},{"id":"5d766314.29f91c","type":"function","z":"98f4cc17.965b","name":"read voice data","func":"//data voice from database\nmsg.topic = \"SELECT VOICE FROM USER\";\nreturn msg; \n\n/*var transcription =msg.transcription;//data from microphone (input data)\n\n\nif(topic==transcription){\n \n //upload name to history database from user database\n msg.topic = INSERT INTO HISTORY (NAME) VALUES ('SELECT NAME FROM USER WHERE VOICE = transcription;');\n \n //audio sound\n msg.payload=\"Welcome\";\n \n \n}\n\nif(topic!=transcription){\n \n //audio sound\n msg.payload=\"Access Denied\";\n \n}*/","outputs":1,"noerr":0,"x":400,"y":360,"wires":[["ee60c3e3.69e03","d97fda3c.851438"]]},{"id":"2b9d8dd1.390142","type":"watson-speech-to-text","z":"98f4cc17.965b","name":"","alternatives":1,"speakerlabels":true,"smartformatting":false,"lang":"en-US","langhidden":"en-US","langcustom":"NoCustomisationSetting","langcustomhidden":"","custom-weight":"0.5","band":"NarrowbandModel","bandhidden":"NarrowbandModel","keywords":"","keywords-threshold":"0.5","word-confidence":false,"password":"","apikey":"aEfplzvlM_B8MA01nsDy3fj6b3CnG6dOQEGISr2gHxxk","payload-response":true,"streaming-mode":false,"streaming-mute":false,"auto-connect":false,"discard-listening":false,"disable-precheck":false,"service-endpoint":"https://api.us-south.speech-to-text.watson.cloud.ibm.com/instances/4ec7115d-1cbf-4ac7-b141-9c9a675fbdac","x":160,"y":340,"wires":[["338d77fb.3e9f88","4428ed4a.f322b4"]]},{"id":"9c343afa.80e438","type":"microphone","z":"98f4cc17.965b","name":"","x":110,"y":240,"wires":[["2b9d8dd1.390142"]]},{"id":"338d77fb.3e9f88","type":"debug","z":"98f4cc17.965b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"transcription","targetType":"msg","x":370,"y":280,"wires":[]},{"id":"31544043.a9475","type":"change","z":"98f4cc17.965b","name":"change to welcome","rules":[{"t":"change","p":"payload","pt":"msg","from":"topic","fromt":"msg","to":"Welcome","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":280,"wires":[["96331e85.67521"]]},{"id":"d97fda3c.851438","type":"switch","z":"98f4cc17.965b","name":"compare data","property":"transcription","propertyType":"msg","rules":[{"t":"eq","v":"topic","vt":"msg"},{"t":"neq","v":"toipc","vt":"msg"}],"checkall":"true","repair":false,"outputs":2,"x":640,"y":340,"wires":[["31544043.a9475","e2ee878e.301618"],["fb2abb1b.bb72f8"]]},{"id":"96331e85.67521","type":"ui_audio","z":"98f4cc17.965b","name":"Output sound","group":"826baa0d.4398d8","voice":"en-GB","always":"","x":920,"y":340,"wires":[]},{"id":"fb2abb1b.bb72f8","type":"change","z":"98f4cc17.965b","name":"change to Access Denied","rules":[{"t":"change","p":"payload","pt":"msg","from":"topic","fromt":"msg","to":"Access Denied","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":400,"wires":[["96331e85.67521"]]},{"id":"e2ee878e.301618","type":"function","z":"98f4cc17.965b","name":"upload name data","func":"msg.voice = msg.payload;\nmsg.name = msg.transcription;\n//msg.transcription = \"SELECT NAME FROM USER WHERE VOICE = msg.name;” \nmsg.topic= \"INSERT INTO HISTORY (NAME) VALUES( \"+ msg.voice+ \");\"\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":180,"wires":[["ee60c3e3.69e03"]]},{"id":"df7c1555.276f08","type":"json","z":"98f4cc17.965b","name":"","property":"payload","action":"","pretty":false,"x":650,"y":100,"wires":[["b7baa5b9.4f62a8"]]},{"id":"b7baa5b9.4f62a8","type":"debug","z":"98f4cc17.965b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":830,"y":100,"wires":[]},{"id":"4428ed4a.f322b4","type":"change","z":"98f4cc17.965b","name":"Transcription","rules":[{"t":"set","p":"payload","pt":"msg","to":"transcription","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":440,"wires":[["5d766314.29f91c"]]},{"id":"7c738c44.e9a364","type":"MySQLdatabase","z":"","host":"165.22.51.44","port":"3306","db":"hireelec_vaes","tz":""},{"id":"826baa0d.4398d8","type":"ui_group","z":"","name":"Default","tab":"1142dd80.c3eec3","disp":true,"width":"6","collapse":false},{"id":"1142dd80.c3eec3","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

Can anyone help me

---

<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:** [23 April 2020 15:40 UTC](https://discourse.nodered.org/t/how-using-msg-topic-payload-and-transcription-in-compare-data-in-switch-node/25365/2 "2020-04-23T15:40:42Z")

</div>

I haven't looked at your flow, but I did notice that you spelled 'topic' wrong in the switch node screenshot. (toipc)

---

<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 April 2020 22:12 UTC](https://discourse.nodered.org/t/how-using-msg-topic-payload-and-transcription-in-compare-data-in-switch-node/25365/3 "2020-04-23T22:12:33Z")

</div>

You might want to change the 'checking all rules' option to 'stop after first match'

---

<div class="post-metadata">

**Author:** ![lingzhongli](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lingzhongli/32/20078_2.png) [@lingzhongli](https://discourse.nodered.org/u/lingzhongli)\
**Post date:** [24 April 2020 13:33 UTC](https://discourse.nodered.org/t/how-using-msg-topic-payload-and-transcription-in-compare-data-in-switch-node/25365/4 "2020-04-24T13:33:11Z")

</div>

At which node?

---

<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:** [24 April 2020 15:18 UTC](https://discourse.nodered.org/t/how-using-msg-topic-payload-and-transcription-in-compare-data-in-switch-node/25365/5 "2020-04-24T15:18:54Z")

</div>

the `switch` node

---

<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:** [23 June 2020 15:19 UTC](https://discourse.nodered.org/t/how-using-msg-topic-payload-and-transcription-in-compare-data-in-switch-node/25365/6 "2020-06-23T15:19:03Z")

</div>

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