# Changing \_msgid

**URL:** <https://discourse.nodered.org/t/changing-msgid/79777>\
**Category:** General\
**Created:** [12 July 2023 17:52 UTC](https://discourse.nodered.org/t/changing-msgid/79777 "2023-07-12T17:52:07Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![hughsheehy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hughsheehy/32/58679_2.png) [@hughsheehy](https://discourse.nodered.org/u/hughsheehy)\
**Post date:** [12 July 2023 17:52 UTC](https://discourse.nodered.org/t/changing-msgid/79777/1 "2023-07-12T17:52:07Z")

</div>

I was looking at this old question ([here](https://discourse.nodered.org/t/question-regarding-msgid/57781)) and have a related question.

If I want to create new msgids on messages, can I do that?

For instance, if I get an array of devices and want to start up a process for each of those devices, I don't think I want each of the messages to have the same \_msgid.

I can iterate through the list of devices and create a new message for each of them inside a function node.  
But how can i change the \_msgid?

I tried a few things and so far the \_msgid remains stubbornly the same.

H

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [12 July 2023 17:58 UTC](https://discourse.nodered.org/t/changing-msgid/79777/2 "2023-07-12T17:58:09Z")

</div>

Why not just use a msg.device property?

---

<div class="post-metadata">

**Author:** ![hughsheehy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hughsheehy/32/58679_2.png) [@hughsheehy](https://discourse.nodered.org/u/hughsheehy)\
**Post date:** [12 July 2023 18:03 UTC](https://discourse.nodered.org/t/changing-msgid/79777/3 "2023-07-12T18:03:31Z")

</div>

It's possible/likely that I don't understand the significance of the \_msgid.

Each message would have its own unique payload, related to the device (a uuid).

I just don't want the messages getting mixed up anywhere down the line, so it seemed sensible to have unique \_msgid. The messages would flow down into logic flows where the data for each device would be gotten from a db and calculations done, with optional flows based on the logic.

That's more or less why I thought that unique \_msgid would be a good idea.

I hope that makes sense!

H

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [12 July 2023 18:08 UTC](https://discourse.nodered.org/t/changing-msgid/79777/4 "2023-07-12T18:08:54Z")

</div>

If you assign the uuid to msg.uuid for example you preserve the uniqueness of each message and process them accordingly. This is exactly the same as having unique \_msgid.

---

<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:** [12 July 2023 18:10 UTC](https://discourse.nodered.org/t/changing-msgid/79777/5 "2023-07-12T18:10:43Z")

</div>

If you use a split node to split your array you will get a discrete message for each array element.

I don't actually know because I've never cared to check but presumably each message has it's own unique msgid?

---

<div class="post-metadata">

**Author:** ![hughsheehy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hughsheehy/32/58679_2.png) [@hughsheehy](https://discourse.nodered.org/u/hughsheehy)\
**Post date:** [12 July 2023 18:15 UTC](https://discourse.nodered.org/t/changing-msgid/79777/6 "2023-07-12T18:15:14Z")

</div>

That sounds good.

So with this, and where each device name is a uuid

```auto
// Input message:
// msg.payload = ["device1", "device2", "device17", "device10", "device2223"]

// Extract the array of chains from the message payload
var devices = msg.payload;

// Iterate over each chain and send a new message for each
for (var i = 0; i < devices.length; i++) {
  var device = devices[i];

  // Create a new message object
  var newMsg = {
    payload: device
  }

  // Send the new message to the next node
  node.send(newMsg);
}

```

I don't have to worry that the messages get mixed up?  
Or should I add something like this?

```auto
 var newMsg = {
    payload: device
    uuid: device
  }

```

or just leave out the payload entirely and have

```auto
 var newMsg = {
    deviceId: device
  }

```

Again, thanks!

H

---

<div class="post-metadata">

**Author:** ![hughsheehy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hughsheehy/32/58679_2.png) [@hughsheehy](https://discourse.nodered.org/u/hughsheehy)\
**Post date:** [12 July 2023 18:20 UTC](https://discourse.nodered.org/t/changing-msgid/79777/7 "2023-07-12T18:20:50Z")

</div>

Yes. That works.

Each new message gets a unique \_msgid.

The split node also adds a section called msg.parts. I'm not sure what that's for.

Thanks very much!

H

---

<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:** [12 July 2023 18:52 UTC](https://discourse.nodered.org/t/changing-msgid/79777/8 "2023-07-12T18:52:50Z")

</div>

> [@hughsheehy](#):
>
> The split node also adds a section called msg.parts. I'm not sure what that's for.

It is to help the `join` node re-assemble the stream of `split` messages back into an array.

---

<div class="post-metadata">

**Author:** ![hughsheehy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hughsheehy/32/58679_2.png) [@hughsheehy](https://discourse.nodered.org/u/hughsheehy)\
**Post date:** [12 July 2023 18:56 UTC](https://discourse.nodered.org/t/changing-msgid/79777/9 "2023-07-12T18:56:55Z")

</div>

Ah! That makes perfect sense. Thanks. Could be very useful later on, actually!

H

---

<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:** [12 July 2023 19:17 UTC](https://discourse.nodered.org/t/changing-msgid/79777/10 "2023-07-12T19:17:55Z")

</div>

If your main programming knowledge is procedural code, every Node-red problem looks like a function problem.

I know it doesn't roll off the tongue like if you have a hammer every problem is a nail but no less wise. 🤪

---

<div class="post-metadata">

**Author:** ![hughsheehy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hughsheehy/32/58679_2.png) [@hughsheehy](https://discourse.nodered.org/u/hughsheehy)\
**Post date:** [12 July 2023 19:26 UTC](https://discourse.nodered.org/t/changing-msgid/79777/11 "2023-07-12T19:26:54Z")

</div>

I tend not to worry too much about the programming paradigm....though I tend not to like Object Oriented unless the objects represent something clearly actually physical, or at least elements in a UI. Otherwise? Not so much.

In any case, thanks for the pointer!

---

<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:** [26 July 2023 19:27 UTC](https://discourse.nodered.org/t/changing-msgid/79777/12 "2023-07-26T19:27:42Z")

</div>

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