Change label for OPC UA-Item

Hello,

I am reading in values from Kepware and then joining the response into a key/value object.
How do I rename the keys from msg.topic to a custom label I assign?

image

Thanks

There are multiple ways.

You could use a change node after the join to move the properties to a better names.

You could pass the msg through a function that splits the topic on . and keeps the last part. Something like this (untested)

const payload = msg.payload;
const result = {};

for (let key in payload) {
    if (payload.hasOwnProperty(key)) {
        const newKey = key.split('.').pop();
        result[newKey] = payload[key];
    }
}

msg.payload = result;
return msg;

Thanks for your response!
Sorry on slow return, busily trying to replace our current tagging engine with node-red.

In the end, I went with your first recommendation on using a change node. For anyone else who comes after, this is how I set it up to update topic name coming from OPC UA Server read:

Using a regular expression search allowed me to ignore the rest of the nodeId returned and just focus on the tag names.

Thanks again!!