# Change name from Device ID

**URL:** <https://discourse.nodered.org/t/change-name-from-device-id/88285>\
**Category:** General\
**Created:** [27 May 2024 07:55 UTC](https://discourse.nodered.org/t/change-name-from-device-id/88285 "2024-05-27T07:55:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kralle](https://avatars.discourse-cdn.com/v4/letter/k/7cd45c/32.png) [@Kralle](https://discourse.nodered.org/u/Kralle)\
**Post date:** [27 May 2024 07:55 UTC](https://discourse.nodered.org/t/change-name-from-device-id/88285/1 "2024-05-27T07:55:53Z")

</div>

Hello, I would like to change the name, for example gps001, so that I can immediately recognize the vehicle's identification in the debug and on the map. What would be the configuration then? Thanks  
 ![Screenshot 2024-05-27 094220](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b609a4824c1e7365cb973b6ada3a5dbbc7d19111.png)

---

<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:** [27 May 2024 08:19 UTC](https://discourse.nodered.org/t/change-name-from-device-id/88285/2 "2024-05-27T08:19:16Z")

</div>

> [@Kralle](#):
>
> I would like to change the name, for example gps001

What would you like to change it to? Is there a fixed relationship between the name and gps number?  
You could create a cross reference table in a context variable eg flow.gps

```auto
{
    "gps001": "Shandong",
    "gps002": "Fujian"
}

```

And a change node  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/e/0e04e9d3317d5ac5e0de1f12ac7d74e448f171ae.png)

---

<div class="post-metadata">

**Author:** ![Kralle](https://avatars.discourse-cdn.com/v4/letter/k/7cd45c/32.png) [@Kralle](https://discourse.nodered.org/u/Kralle)\
**Post date:** [27 May 2024 08:26 UTC](https://discourse.nodered.org/t/change-name-from-device-id/88285/3 "2024-05-27T08:26:48Z")

</div>

Yes... the trackers are permanently assigned.  
gps001 = NOR X1  
gps002 = PUA X2

And NOR and PUA should be displayed on the map not gps001 gps002 and so on

How to create a cross reference table in a context variable eg flow.gps?  
 ![Screenshot 2024-05-27 103940](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/7/b7feba0d22e4f8b6aa4094c881aefcce1e1f9f06.png)

---

<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:** [27 May 2024 08:55 UTC](https://discourse.nodered.org/t/change-name-from-device-id/88285/4 "2024-05-27T08:55:23Z")

</div>

> [@Kralle](#):
>
> How to create a cross reference table in a context variable eg flow.gps?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/19e6456bef28f20406a628119543e0dcf44e8e49.png)

```auto
[{"id":"f0253ad934fa6c83","type":"group","z":"c1759c372b184d6a","name":"Populate flow.gps","style":{"label":true},"nodes":["36c8f2e88a35e273","81d2c5110ad10bcc"],"x":94,"y":79,"w":352,"h":82},{"id":"36c8f2e88a35e273","type":"inject","z":"c1759c372b184d6a","g":"f0253ad934fa6c83","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"go","payloadType":"str","x":190,"y":120,"wires":[["81d2c5110ad10bcc"]]},{"id":"81d2c5110ad10bcc","type":"change","z":"c1759c372b184d6a","g":"f0253ad934fa6c83","name":"","rules":[{"t":"set","p":"gps","pt":"flow","to":"{\"gps001\":\"Fujian\",\"gps002\":\"Shandong\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":120,"wires":[[]]}]

```

> [@Kralle](#):
>
> NOR and PUA should be displayed on the map not gps001 gps002

I don't know anything about the map you are using but it must be getting "gps001" from somewhere, perhaps from msg.name.  
If you change msg.name as I showed above, won't that change be shown on the map?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [27 May 2024 10:22 UTC](https://discourse.nodered.org/t/change-name-from-device-id/88285/5 "2024-05-27T10:22:47Z")

</div>

If it's node-red-contrib-web-worldmap then it needs to set `msg.payload.name`

---

<div class="post-metadata">

**Author:** ![Kralle](https://avatars.discourse-cdn.com/v4/letter/k/7cd45c/32.png) [@Kralle](https://discourse.nodered.org/u/Kralle)\
**Post date:** [27 May 2024 12:31 UTC](https://discourse.nodered.org/t/change-name-from-device-id/88285/6 "2024-05-27T12:31:26Z")

</div>

Thanks deejay. Yes... simply put, the flow works with 3 nodes and 1 tracker display (MQTT-IN, a function node and node -red-contrib-web-wordmap. Since wordmap requires at least name, lat and log, I have the function node configured as shown in the picture.  
 ![Screenshot 2024-05-27 143036](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/c/2c244128f99984367603e1f83ffb77d7a9e77f50.png)  
 ![Screenshot 2024-05-27 143056](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/115e4caf776ed76d2b4c7006f41393febbd145b2.png)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [27 May 2024 17:24 UTC](https://discourse.nodered.org/t/change-name-from-device-id/88285/7 "2024-05-27T17:24:51Z")

</div>

So yes - use a lookup like @jbudd suggests (Or hardcode it in the function if it is not really going to change or get too big) - but in the change node use Set : msg.payload.name to the value flow.gps[msg.payload.name]

---

<div class="post-metadata">

**Author:** ![Kralle](https://avatars.discourse-cdn.com/v4/letter/k/7cd45c/32.png) [@Kralle](https://discourse.nodered.org/u/Kralle)\
**Post date:** [28 May 2024 08:28 UTC](https://discourse.nodered.org/t/change-name-from-device-id/88285/8 "2024-05-28T08:28:10Z")

</div>

I now have the solution... very simple. I simply installed a change node between MQTT-IN and FUNCTION (see screenshot)

 ![Screenshot 2024-05-28 102122](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/f/5f2fac55e9cad35778e109c2c472251c55e2d858.png)

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [28 May 2024 19:35 UTC](https://discourse.nodered.org/t/change-name-from-device-id/88285/9 "2024-05-28T19:35:30Z")

</div>

> [@Kralle](#):
>
> I have the function node configured as shown in the picture.  
> ![Screenshot 2024-05-27 143036](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/c/2c244128f99984367603e1f83ffb77d7a9e77f50.png)

On line #6 you have wiped out the incoming `msg` object, with any other properties that may have been set upstream -- generally, that is considered bad form. Instead you can delete that line, and just set your payload to the new object containing the lat, long, name properties.

Not that is matters now, since that last solution uses a `change` node that preserves the other fields... but just in case someone later tries that same code... fwiw.

---

<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:** [11 June 2024 19:36 UTC](https://discourse.nodered.org/t/change-name-from-device-id/88285/10 "2024-06-11T19:36:07Z")

</div>

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