# Create function node to send msg.payload.variableValue from existing msg.payload

**URL:** <https://discourse.nodered.org/t/create-function-node-to-send-msg-payload-variablevalue-from-existing-msg-payload/70210>\
**Category:** General\
**Tags:** function-node, mqtt, opcua\
**Created:** [7 November 2022 11:37 UTC](https://discourse.nodered.org/t/create-function-node-to-send-msg-payload-variablevalue-from-existing-msg-payload/70210 "2022-11-07T11:37:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![faulehenne](https://avatars.discourse-cdn.com/v4/letter/f/9f8e36/32.png) [@faulehenne](https://discourse.nodered.org/u/faulehenne)\
**Post date:** [7 November 2022 11:37 UTC](https://discourse.nodered.org/t/create-function-node-to-send-msg-payload-variablevalue-from-existing-msg-payload/70210/1 "2022-11-07T11:37:59Z")

</div>

Hey,  
i'm building a connection between an MQTT Input and an OPC-UA Server (node-red-contrib-opcua).

To give the opc-ua server node a value i need to send my value from the MQTT input as "msg.payload.variableValue". I'm trying to achieve this by using the function node. My OPC-UA Server debugger tells me the variableValue is missing and it seems i can't figure out how to give this value to the server node.

This is the flow i'm using:

```auto
[{"id":"cfb91e4987f2c163","type":"tab","label":"Flow 1 Paul","disabled":false,"info":"","env":[]},{"id":"abf7079a.653be8","type":"mqtt in","z":"cfb91e4987f2c163","name":"","topic":"esp32/temperature","qos":"2","datatype":"utf8","broker":"10e78a89.5b4fd5","nl":false,"rap":false,"rh":"0","inputs":0,"x":150,"y":260,"wires":[["470a98984a913228","d65592b613ad7c29"]]},{"id":"ee410d56cb73180b","type":"OpcUa-Server","z":"cfb91e4987f2c163","port":"4841","name":"NROPC","endpoint":"","users":"users.json","nodesetDir":"","folderName4PKI":"","autoAcceptUnknownCertificate":true,"registerToDiscovery":false,"constructDefaultAddressSpace":true,"allowAnonymous":true,"endpointNone":true,"endpointSign":true,"endpointSignEncrypt":true,"endpointBasic128Rsa15":true,"endpointBasic256":true,"endpointBasic256Sha256":true,"maxNodesPerBrowse":"1000","maxNodesPerHistoryReadData":0,"maxNodesPerHistoryReadEvents":0,"maxNodesPerHistoryUpdateData":0,"maxNodesPerRead":"1000","maxNodesPerWrite":"1000","maxNodesPerMethodCall":0,"maxNodesPerRegisterNodes":0,"maxNodesPerNodeManagement":0,"maxMonitoredItemsPerCall":0,"maxNodesPerHistoryUpdateEvents":0,"maxNodesPerTranslateBrowsePathsToNodeIds":0,"maxConnectionsPerEndpoint":"1000","maxMessageSize":4096,"maxBufferSize":4096,"x":560,"y":140,"wires":[["3e828e8b98926363"]]},{"id":"3e828e8b98926363","type":"debug","z":"cfb91e4987f2c163","name":"debug 3","active":false,"tosidebar":false,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":750,"y":140,"wires":[]},{"id":"9a4ac34d270b0fa5","type":"inject","z":"cfb91e4987f2c163","name":"add BME688_TEMP (FLOAT)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ns=1;s=BME688_TEMP;datatype=Float","payload":"{\"opcuaCommand\":\"addVariable\"}","payloadType":"json","x":180,"y":140,"wires":[["ee410d56cb73180b"]]},{"id":"854f1b9146b1e3fe","type":"inject","z":"cfb91e4987f2c163","d":true,"name":"Set TestVariable2 23.4","props":[{"p":"payload.messageType","v":"Variable","vt":"str"},{"p":"payload.variableName","v":"BME688_TEMP","vt":"str"},{"p":"payload.datatype","v":"Float","vt":"str"},{"p":"payload.namespace","v":"1","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":160,"y":200,"wires":[["ee410d56cb73180b"]]},{"id":"470a98984a913228","type":"debug","z":"cfb91e4987f2c163","name":"debug 4","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":750,"y":260,"wires":[]},{"id":"d65592b613ad7c29","type":"function","z":"cfb91e4987f2c163","name":"function 1","func":"var newMsg = { payload : msg.payload.variableValue = msg.payload };\nreturn newMsg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":300,"wires":[["3266d2d1ac095ebe","ee410d56cb73180b"]]},{"id":"3266d2d1ac095ebe","type":"debug","z":"cfb91e4987f2c163","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":740,"y":320,"wires":[]},{"id":"10e78a89.5b4fd5","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

I'd be happy about any help, thanks in advance.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [7 November 2022 12:04 UTC](https://discourse.nodered.org/t/create-function-node-to-send-msg-payload-variablevalue-from-existing-msg-payload/70210/2 "2022-11-07T12:04:51Z")

</div>

You can certainly do it with a function node, better to use a change node.

Here are both approaches below your own function node.

 ![Untitled 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/f/0fdf6540bd029d8ba81e78e4c9f972ce696cba88.jpeg)

```auto
[{"id":"d65592b613ad7c29","type":"function","z":"cfb91e4987f2c163","name":"function 1","func":"var newMsg = { payload : msg.payload.variableValue = msg.payload };\nreturn newMsg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":60,"wires":[["3266d2d1ac095ebe"]]},{"id":"3266d2d1ac095ebe","type":"debug","z":"cfb91e4987f2c163","name":"Function 1","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":850,"y":60,"wires":[]},{"id":"53731864e178231d","type":"inject","z":"cfb91e4987f2c163","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":440,"y":120,"wires":[["d65592b613ad7c29","a344f3fc27b494e1","d3d2b006a4a4c2b7"]]},{"id":"a344f3fc27b494e1","type":"function","z":"cfb91e4987f2c163","name":"function 18","func":"msg.payload = {variableValue: msg.payload };\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":630,"y":120,"wires":[["e3822e7944ecdf5f"]]},{"id":"d3d2b006a4a4c2b7","type":"change","z":"cfb91e4987f2c163","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.variableValue","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":180,"wires":[["85f31e28068135b9"]]},{"id":"e3822e7944ecdf5f","type":"debug","z":"cfb91e4987f2c163","name":"Function 18","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":850,"y":120,"wires":[]},{"id":"85f31e28068135b9","type":"debug","z":"cfb91e4987f2c163","name":"Change node","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":860,"y":180,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![faulehenne](https://avatars.discourse-cdn.com/v4/letter/f/9f8e36/32.png) [@faulehenne](https://discourse.nodered.org/u/faulehenne)\
**Post date:** [8 November 2022 07:50 UTC](https://discourse.nodered.org/t/create-function-node-to-send-msg-payload-variablevalue-from-existing-msg-payload/70210/3 "2022-11-08T07:50:44Z")

</div>

hey, thanks for your help. I've tried to figure it out with a change node but it doesn't work like intended. Any ideas on what i'm doing wrong? I think it might rather be an issue with how i give the variableValue to the OPC-UA Server at this point. When i observe the Server with a client i get 0 as a value for the temperature.

This is the code i'm using:

```auto
[{"id":"cfb91e4987f2c163","type":"tab","label":"Flow 1 Paul","disabled":false,"info":"","env":[]},{"id":"c802b424839907e3","type":"junction","z":"cfb91e4987f2c163","x":400,"y":200,"wires":[["ee410d56cb73180b"]]},{"id":"abf7079a.653be8","type":"mqtt in","z":"cfb91e4987f2c163","name":"","topic":"esp32/temperature","qos":"2","datatype":"utf8","broker":"10e78a89.5b4fd5","nl":false,"rap":false,"rh":"0","inputs":0,"x":150,"y":260,"wires":[["470a98984a913228","e54464b5614c69fc"]]},{"id":"ee410d56cb73180b","type":"OpcUa-Server","z":"cfb91e4987f2c163","port":"4841","name":"NROPC","endpoint":"","users":"users.json","nodesetDir":"","folderName4PKI":"","autoAcceptUnknownCertificate":true,"registerToDiscovery":false,"constructDefaultAddressSpace":true,"allowAnonymous":true,"endpointNone":true,"endpointSign":true,"endpointSignEncrypt":true,"endpointBasic128Rsa15":true,"endpointBasic256":true,"endpointBasic256Sha256":true,"maxNodesPerBrowse":"1000","maxNodesPerHistoryReadData":0,"maxNodesPerHistoryReadEvents":0,"maxNodesPerHistoryUpdateData":0,"maxNodesPerRead":"1000","maxNodesPerWrite":"1000","maxNodesPerMethodCall":0,"maxNodesPerRegisterNodes":0,"maxNodesPerNodeManagement":0,"maxMonitoredItemsPerCall":0,"maxNodesPerHistoryUpdateEvents":0,"maxNodesPerTranslateBrowsePathsToNodeIds":0,"maxConnectionsPerEndpoint":"1000","maxMessageSize":4096,"maxBufferSize":4096,"x":620,"y":140,"wires":[["3e828e8b98926363"]]},{"id":"3e828e8b98926363","type":"debug","z":"cfb91e4987f2c163","name":"debug 3","active":false,"tosidebar":false,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":790,"y":140,"wires":[]},{"id":"9a4ac34d270b0fa5","type":"inject","z":"cfb91e4987f2c163","name":"add BME688_TEMP (FLOAT)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"ns=1;s=BME688_TEMP;datatype=Float","payload":"{\"opcuaCommand\":\"addVariable\"}","payloadType":"json","x":180,"y":140,"wires":[["ee410d56cb73180b"]]},{"id":"854f1b9146b1e3fe","type":"inject","z":"cfb91e4987f2c163","d":true,"name":"Set TestVariable2 23.4","props":[{"p":"payload.messageType","v":"Variable","vt":"str"},{"p":"payload.variableName","v":"BME688_TEMP","vt":"str"},{"p":"payload.datatype","v":"Float","vt":"str"},{"p":"payload.namespace","v":"1","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":200,"wires":[["c802b424839907e3"]]},{"id":"470a98984a913228","type":"debug","z":"cfb91e4987f2c163","name":"debug 4","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":750,"y":260,"wires":[]},{"id":"e54464b5614c69fc","type":"change","z":"cfb91e4987f2c163","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.variableValue","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":300,"wires":[["8e2cc42f5cd0e5b6","c802b424839907e3"]]},{"id":"8e2cc42f5cd0e5b6","type":"debug","z":"cfb91e4987f2c163","name":"debug 9","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":750,"y":340,"wires":[]},{"id":"10e78a89.5b4fd5","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [8 November 2022 09:19 UTC](https://discourse.nodered.org/t/create-function-node-to-send-msg-payload-variablevalue-from-existing-msg-payload/70210/4 "2022-11-08T09:19:53Z")

</div>

If you want to make the property name variable you would do it like this

```auto
[{"id":"53731864e178231d","type":"inject","z":"cfb91e4987f2c163","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":440,"wires":[["a344f3fc27b494e1","d3d2b006a4a4c2b7"]]},{"id":"a344f3fc27b494e1","type":"function","z":"cfb91e4987f2c163","name":"function 18","func":"let variableValue = \"test\";\nmsg.payload = {[variableValue]: msg.payload };\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":440,"wires":[["e3822e7944ecdf5f"]]},{"id":"d3d2b006a4a4c2b7","type":"change","z":"cfb91e4987f2c163","name":"","rules":[{"t":"set","p":"variableValue","pt":"msg","to":"test","tot":"str"},{"t":"move","p":"payload","pt":"msg","to":"payload[msg.variableValue]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":500,"wires":[["85f31e28068135b9"]]},{"id":"e3822e7944ecdf5f","type":"debug","z":"cfb91e4987f2c163","name":"Function 18","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":610,"y":440,"wires":[]},{"id":"85f31e28068135b9","type":"debug","z":"cfb91e4987f2c163","name":"Change node","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":620,"y":500,"wires":[]}]

```

```auto
let variableValue = "test";
msg.payload = {[variableValue]: msg.payload };
return msg;

```

---

<div class="post-metadata">

**Author:** ![faulehenne](https://avatars.discourse-cdn.com/v4/letter/f/9f8e36/32.png) [@faulehenne](https://discourse.nodered.org/u/faulehenne)\
**Post date:** [9 November 2022 17:57 UTC](https://discourse.nodered.org/t/create-function-node-to-send-msg-payload-variablevalue-from-existing-msg-payload/70210/5 "2022-11-09T17:57:43Z")

</div>

Hey thanks for the help. I still can't figure out how to give the msg.payload.variableValue to the OPC Server. Could you show me how to implement your solution into my flow?

Edit: I think the problem is how to join the messages from the node which sets the Variable and the MQTT node from which i change msg.payload to msg.payload.variableValue but i might be wrong...

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 November 2022 20:06 UTC](https://discourse.nodered.org/t/create-function-node-to-send-msg-payload-variablevalue-from-existing-msg-payload/70210/6 "2022-11-09T20:06:00Z")

</div>

> [@faulehenne](#):
>
> I think the problem is how to join the messages from the node which sets the Variable and the MQTT node from which i change msg.payload to msg.payload.variableValue but i might be wrong...

See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

---

<div class="post-metadata">

**Author:** ![mikakaraila](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikakaraila/32/37496_2.png) [@mikakaraila](https://discourse.nodered.org/u/mikakaraila)\
**Post date:** [10 November 2022 18:37 UTC](https://discourse.nodered.org/t/create-function-node-to-send-msg-payload-variablevalue-from-existing-msg-payload/70210/7 "2022-11-10T18:37:39Z")

</div>

Just for others who have interested discussion was also here:

> <https://github.com/mikakaraila/node-red-contrib-opcua/issues/492>
>
> Hey,
> 
> I'm trying to display Data i receive via MQTT to a NodeRed OPC-UA Server… using this flow:
> 
> \`\[{"id":"cfb91e4987f2c163","type":"tab","label":"Flow 1","disabled":false,"info":"","env":\[\]},{"id":"9e58624.7faaba","type":"mqtt out","z":"cfb91e4987f2c163","name":"","topic":"esp32/output","qos":"","retain":"","broker":"10e78a89.5b4fd5","x":700,"y":680,"wires":\[\]},{"id":"abf7079a.653be8","type":"mqtt in","z":"cfb91e4987f2c163","name":"","topic":"esp32/temperature","qos":"2","datatype":"utf8","broker":"10e78a89.5b4fd5","nl":false,"rap":false,"rh":"0","inputs":0,"x":110,"y":340,"wires":\[\["cc79021b.9a751","21eae8f8.2971b8","2cfb0e72db40f97b"\]\]},{"id":"83cf37cf.c76988","type":"ui\_switch","z":"cfb91e4987f2c163","name":"","label":"Output","group":"61285987.c20328","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"off","offvalueType":"str","officon":"","offcolor":"","x":90,"y":680,"wires":\[\["9e58624.7faaba"\]\]},{"id":"cc79021b.9a751","type":"debug","z":"cfb91e4987f2c163","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":360,"y":280,"wires":\[\]},{"id":"21eae8f8.2971b8","type":"ui\_chart","z":"cfb91e4987f2c163","name":"","group":"61285987.c20328","order":0,"width":0,"height":0,"label":"Temperature","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":\["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"\],"outputs":1,"useDifferentColor":false,"className":"","x":350,"y":360,"wires":\[\[\]\]},{"id":"3680437c4c28f34d","type":"mqtt in","z":"cfb91e4987f2c163","name":"","topic":"esp32/pressure","qos":"2","datatype":"auto-detect","broker":"10e78a89.5b4fd5","nl":false,"rap":true,"rh":0,"inputs":0,"x":100,"y":200,"wires":\[\["22cf59c45ea91f6c"\]\]},{"id":"22cf59c45ea91f6c","type":"ui\_chart","z":"cfb91e4987f2c163","name":"","group":"61285987.c20328","order":0,"width":0,"height":0,"label":"Pressure","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":\["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"\],"outputs":1,"useDifferentColor":false,"className":"","x":400,"y":200,"wires":\[\[\]\]},{"id":"2cfb0e72db40f97b","type":"OpcUa-Item","z":"cfb91e4987f2c163","item":"ns=1;s=PaulsTemp;datatype=String","datatype":"String","value":"\\"Test\\"","name":"Temperatur","x":350,"y":480,"wires":\[\["abd9b31982756ab9","ee410d56cb73180b"\]\]},{"id":"abd9b31982756ab9","type":"debug","z":"cfb91e4987f2c163","name":"debug 1","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":650,"y":360,"wires":\[\]},{"id":"ee410d56cb73180b","type":"OpcUa-Server","z":"cfb91e4987f2c163","port":"4841","name":"NROPC","endpoint":"","users":"users.json","nodesetDir":"","folderName4PKI":"","autoAcceptUnknownCertificate":true,"registerToDiscovery":false,"constructDefaultAddressSpace":true,"allowAnonymous":true,"endpointNone":true,"endpointSign":true,"endpointSignEncrypt":true,"endpointBasic128Rsa15":true,"endpointBasic256":true,"endpointBasic256Sha256":true,"maxNodesPerBrowse":"1000","maxNodesPerHistoryReadData":0,"maxNodesPerHistoryReadEvents":0,"maxNodesPerHistoryUpdateData":0,"maxNodesPerRead":"1000","maxNodesPerWrite":"1000","maxNodesPerMethodCall":0,"maxNodesPerRegisterNodes":0,"maxNodesPerNodeManagement":0,"maxMonitoredItemsPerCall":0,"maxNodesPerHistoryUpdateEvents":0,"maxNodesPerTranslateBrowsePathsToNodeIds":0,"maxConnectionsPerEndpoint":"1000","maxMessageSize":4096,"maxBufferSize":4096,"x":640,"y":560,"wires":\[\["3e828e8b98926363"\]\]},{"id":"55f96a62301a0227","type":"inject","z":"cfb91e4987f2c163","name":"addVariable","props":\[{"p":"payload"},{"p":"topic","vt":"str"}\],"repeat":"1","crontab":"","once":true,"onceDelay":"5","topic":"ns=1;s=PaulsTemp;datatype=String","payload":"{ \\"opcuaCommand\\": \\"addVariable\\"}","payloadType":"json","x":130,"y":480,"wires":\[\["2cfb0e72db40f97b"\]\]},{"id":"3e828e8b98926363","type":"debug","z":"cfb91e4987f2c163","name":"debug 3","active":false,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":870,"y":560,"wires":\[\]},{"id":"10e78a89.5b4fd5","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"61285987.c20328","type":"ui\_group","name":"Main","tab":"e7c46d5e.a1283","order":1,"disp":true,"width":"6","collapse":false},{"id":"e7c46d5e.a1283","type":"ui\_tab","name":"Dashboard","icon":"dashboard"}\]\`
> 
> 
> The debugger for my OPC-UA Server is giving me this error message: "warning: properties like messageType, namespace,
> variableName or VariableValue is missing." and my Client (UAExpert) is showing the Variable with no Value at all. I can't figure out how to tell the OPC-UA Server where to look for the value it is missing. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![faulehenne](https://avatars.discourse-cdn.com/v4/letter/f/9f8e36/32.png) [@faulehenne](https://discourse.nodered.org/u/faulehenne)\
**Post date:** [14 November 2022 09:04 UTC](https://discourse.nodered.org/t/create-function-node-to-send-msg-payload-variablevalue-from-existing-msg-payload/70210/8 "2022-11-14T09:04:50Z")

</div>

Thanks colin, i tried to join a complete message to create a merged object but i still don't get any value in UAExpert (OPC-UA Client).

I also added string to number conversion for my MQTT input value which then is inserted to the change node, moving msg.payload to msg.payload.variableValue

---

<div class="post-metadata">

**Author:** ![faulehenne](https://avatars.discourse-cdn.com/v4/letter/f/9f8e36/32.png) [@faulehenne](https://discourse.nodered.org/u/faulehenne)\
**Post date:** [14 November 2022 12:01 UTC](https://discourse.nodered.org/t/create-function-node-to-send-msg-payload-variablevalue-from-existing-msg-payload/70210/9 "2022-11-14T12:01:06Z")

</div>

I got it to work: I used a function node to solve my issue. The function node sets messageType, variableName, datatype and namespace and it takes the old msg.payload and set's it as the variableValue.

The code i used in the function node:

```auto
var temperature =msg.payload;
msg.payload = { messageType : "Variable", variableName : "BME688_TEMP", datatype: "Float", namespace: "1", variableValue: temperature };
return msg;

```

Thanks for all the help.

---

<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:** [28 November 2022 12:01 UTC](https://discourse.nodered.org/t/create-function-node-to-send-msg-payload-variablevalue-from-existing-msg-payload/70210/10 "2022-11-28T12:01:07Z")

</div>

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