# Incrementing a payload msg and formatting a string

**URL:** <https://discourse.nodered.org/t/incrementing-a-payload-msg-and-formatting-a-string/87142>\
**Category:** General\
**Created:** [11 April 2024 02:04 UTC](https://discourse.nodered.org/t/incrementing-a-payload-msg-and-formatting-a-string/87142 "2024-04-11T02:04:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaredlgeorge](https://avatars.discourse-cdn.com/v4/letter/j/8e7dd6/32.png) [@jaredlgeorge](https://discourse.nodered.org/u/jaredlgeorge)\
**Post date:** [11 April 2024 02:04 UTC](https://discourse.nodered.org/t/incrementing-a-payload-msg-and-formatting-a-string/87142/1 "2024-04-11T02:04:18Z")

</div>

I need to send 1rt 1-1 to a udp node. When I send the msg.payload I need to start the output with 1rt 1-1 and increment the last number by 1 until it gets to 17. Example 1rt 1-1, 1rt 1-2, 1rt 1-3 ..... 1rt 1-17. Once it gets to 17 I need to start the incrementing to 1rt 2-1, 1rt 2-2, 1rt 2-3,...... 1rt 2-17.

This will happen 12 to 13 times.

When I receive the udp stream it comes in like this \>2:T1-17,1,64F. I need the format to be 2,1,17,1,64.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [11 April 2024 04:57 UTC](https://discourse.nodered.org/t/incrementing-a-payload-msg-and-formatting-a-string/87142/2 "2024-04-11T04:57:55Z")

</div>

# The first part.

Well, I guess you could write a bit of Javascript and make things happen.

That depends on how good you are at writing JS code though.

I'm not sure where the `this will happen 12 to 13 times` comes into it though.

eg code:

```auto
// set up initial values and increment them as needed.
let a = 0;
let b = 1

// message received.
a = a + 1;
msg = {"payload" : "1rt " + b + "-" + "a"};
//
return msg;

```

This will work to the point that you would get `1rt 1-x` where x just keeps growing.

You will need to build on that so when `a == 17` (or more so `18`) it loops back and increments `b` and sets `a` to `1`.

I won't do that for you at this point as I think it may be better you try and see if you can do it.  
If you get stuck I may be able to help you - or anyone else here.

# The second part:

You are going to have to `split` that message a lot of times to break it down to those parts.  
There is/are nodes that would do it, but I think that you would/may be better off doing it all in one `function` node - again: depending on how good you are at JS.

I hope that/this helps you.

---

<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:** [10 July 2024 04:58 UTC](https://discourse.nodered.org/t/incrementing-a-payload-msg-and-formatting-a-string/87142/3 "2024-07-10T04:58:34Z")

</div>

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