Code function for change format data from Kepware to Power BI

Who know about code function for change format data from Kepware like picture below

to API of Power BI format as
[

{

"RANDOM_NUM" :98.6

}

]
Thank you.

??? You just write some javascript code, pick the value you are interested in from the incoming message, then you just insert it and format it in a new message that you send
Where do you find/see 98.6 ??

v = RANDOM_NUM

In a change node you can
set msg. payload[0].RANDOM_NUM
to value of msg. payload.values[0].v

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path/value to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

1 Like

There are many ways, however, in the interest of speed, a function node containing ...

msg.payload = [ { RANDOM_NUM: msg.payload.values[0].v } ]
return msg

... will work.

Also possible with a change node, a template node and others.


In future, please post sample data instead of a screenshot (we can use sample data in a working example without having to type stuff out)

Canned tips for newcomer

Getting the EXACT path (like msg.payload.values[0].v) and copying usable data

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

How to post Code properly

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

Recommended essential playlist to get up to speed quickly

I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

1 Like

Thank you very much. It very clear.

Thank you very much. It very clear.

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