# Change label for OPC UA-Item

**URL:** <https://discourse.nodered.org/t/change-label-for-opc-ua-item/95010>\
**Category:** General\
**Tags:** opcua\
**Created:** [30 January 2025 18:18 UTC](https://discourse.nodered.org/t/change-label-for-opc-ua-item/95010 "2025-01-30T18:18:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![d3rpy\_f1sh](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@d3rpy\_f1sh](https://discourse.nodered.org/u/d3rpy_f1sh)\
**Post date:** [30 January 2025 18:18 UTC](https://discourse.nodered.org/t/change-label-for-opc-ua-item/95010/1 "2025-01-30T18:18:56Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/b/7baa0ee932a9559c5c32dbaaac3c19c9401705a8.png)

Thanks

---

<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:** [2 February 2025 09:49 UTC](https://discourse.nodered.org/t/change-label-for-opc-ua-item/95010/2 "2025-02-02T09:49:40Z")

</div>

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)

```js
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;

```

---

<div class="post-metadata">

**Author:** ![d3rpy\_f1sh](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@d3rpy\_f1sh](https://discourse.nodered.org/u/d3rpy_f1sh)\
**Post date:** [6 February 2025 19:15 UTC](https://discourse.nodered.org/t/change-label-for-opc-ua-item/95010/3 "2025-02-06T19:15:52Z")

</div>

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:

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

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

Thanks again!!

---

<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:** [20 February 2025 19:16 UTC](https://discourse.nodered.org/t/change-label-for-opc-ua-item/95010/4 "2025-02-20T19:16:21Z")

</div>

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