# Best way to concatenate content over time?

**URL:** <https://discourse.nodered.org/t/best-way-to-concatenate-content-over-time/37574>\
**Category:** General\
**Created:** [16 December 2020 11:43 UTC](https://discourse.nodered.org/t/best-way-to-concatenate-content-over-time/37574 "2020-12-16T11:43:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bltDefender](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bltdefender/32/33722_2.png) [@bltDefender](https://discourse.nodered.org/u/bltDefender)\
**Post date:** [16 December 2020 11:43 UTC](https://discourse.nodered.org/t/best-way-to-concatenate-content-over-time/37574/1 "2020-12-16T11:43:07Z")

</div>

I do have a process consisting of several functions and api calls which is looped until all api responses have been processed. every time a loop cycle ends, there is some content being generated (f.e. "result of loop 1", "result of loop 2" and so on) I would like show this on the dashboard but need to concat all the content first. I tried to simply grow a variable like flow.processContent += msg.payload.generatedOutput but failed to show this flow variable in the dashboard template. Even my plays with the join node did not really do the job. What would be the best way to achieve this?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 December 2020 12:00 UTC](https://discourse.nodered.org/t/best-way-to-concatenate-content-over-time/37574/2 "2020-12-16T12:00:27Z")

</div>

Using a flow variable should work. Show us what you have achieved and tell us what isn't working.

---

<div class="post-metadata">

**Author:** ![bltDefender](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bltdefender/32/33722_2.png) [@bltDefender](https://discourse.nodered.org/u/bltDefender)\
**Post date:** [16 December 2020 12:53 UTC](https://discourse.nodered.org/t/best-way-to-concatenate-content-over-time/37574/3 "2020-12-16T12:53:08Z")

</div>

![Bildschirmfoto 2020-12-16 um 13.22.26](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd6c6f00299c37323abb7cb951ac213d02460c14.png)

initially I set flow.chickenLocations to "CHICKEN" on the third node.  
 ![Bildschirmfoto 2020-12-16 um 13.24.29](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/cac169eaa4025b032d379163fa970f7bb7db2190.png)

on the last function node I modify this flow variable like this (just as poc):

```auto
let arr = msg.payload.routes[0];

let dist = arr.distance;
if(dist <= msg.maxDistance)
{
    flow.chickenLocations = flow.chickenLocations + msg.myData.b + "(" + msg.myData.c +")<br>";
    return {locData: msg.myData, payload: msg.payload, distance: dist};
}

```

the template node should then simply get updated and display that variable with its current content

```auto
<div ng-bind-html="flow.chickenLocations"></div>

```

Nothing is shown on the template node, so I must be doing something wrong....

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 December 2020 13:45 UTC](https://discourse.nodered.org/t/best-way-to-concatenate-content-over-time/37574/4 "2020-12-16T13:45:32Z")

</div>

The first thing I note is that you are not using the recommended way to access context data in a function node as described in the [node-red docs](https://nodered.org/docs/user-guide/writing-functions).

Apart from that, which bit isn't working? Setting the context data or picking it up in the template?

You also might like to look at the help text for the Template node.

---

<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:** [14 February 2021 13:46 UTC](https://discourse.nodered.org/t/best-way-to-concatenate-content-over-time/37574/5 "2021-02-14T13:46:03Z")

</div>

Closed on 14 February 2021 13:46 UTC

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