# Payload parser assign predetermined group values to variables

**URL:** https://community.tago.io/t/payload-parser-assign-predetermined-group-values-to-variables/1408
**Category:** Analysis and Actions
**Created:** [June 12, 2023, 8:03pm UTC](https://community.tago.io/t/payload-parser-assign-predetermined-group-values-to-variables/1408 "2023-06-12T20:03:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![info\_5](https://avatars.discourse-cdn.com/v4/letter/i/9fc348/32.png) [@info\_5](https://community.tago.io/u/info_5)
#### Post date: [June 12, 2023, 8:03pm UTC](https://community.tago.io/t/payload-parser-assign-predetermined-group-values-to-variables/1408/1 "2023-06-12T20:03:26Z")

</div>

Hi,

I have used a mqtt csv parser to get comma delimited values of a variable into cast number values. I use the same variable name so im getting the same variables with different values. I need to assign now predetermined group values in order to see them all in a table widget. right know they are getting the same group values and I only see one of the values in the table. Can someone please help with the code to be able to see all values in one table

```auto
const mqtt_payload = payload.find((data) => data.variable === "ids" || (data.metadata && data.metadata.mqtt_topic));if (mqtt_payload) { const data = [{ variable: 'id', value: Number(splitted_value[1]),}, { variable: 'id', value: Number(splitted_value[2]),}, { variable: 'id', value: Number(splitted_value[3]),}, ]; const group = String(new Date().getTime()); payload = payload.concat(data).map(x => ({ ...x, group }));

}

```

---

<div class="post-metadata">

### Author: ![ischacht](https://avatars.discourse-cdn.com/v4/letter/i/ee7513/32.png) [@ischacht](https://community.tago.io/u/ischacht)
#### Post date: [June 13, 2023, 2:45am UTC](https://community.tago.io/t/payload-parser-assign-predetermined-group-values-to-variables/1408/2 "2023-06-13T02:45:12Z")

</div>

Well of course, you’re grouping all your inputs under the same variable AND under the same group/series. The widget will only display whatever data arrived last, as if the other values were crushed.

I don’t really get how’s your payload to begin with, but the case your described was that you wanted the keep the same variable, but have a different group for each input, right?

The easiest could be to add a number (perhaps an index?) to your group-timestamp while it’s in int form, then cast it to string. Altough, given how JS works you an just add a number to a string and should work lol.

const mqtt\_payload = payload.find((data) =\> data.variable === “ids” || (data.metadata && data.metadata.mqtt\_topic));

if (mqtt\_payload) {

```
const group \= new Date().getTime();

const data \= \[

    { variable: 'id', value: Number(splitted\_value\[1\]), group: String(group + 1) },

    { variable: 'id', value: Number(splitted\_value\[2\]), group: String(group + 2) },

    { variable: 'id', value: Number(splitted\_value\[3\]), group: String(group + 3) },

\];

payload.concat(data);

```

}

The thing that I don’t like for this approach is that it looks somewhat dirty but it can work.

Edit: last line of code
