# Combining strings (Referencing csv and picking a specific value based on a global value)

**URL:** https://discourse.nodered.org/t/combining-strings-referencing-csv-and-picking-a-specific-value-based-on-a-global-value/49276
**Category:** General
**Created:** [3 August 2021 17:00 UTC](https://discourse.nodered.org/t/combining-strings-referencing-csv-and-picking-a-specific-value-based-on-a-global-value/49276 "2021-08-03T17:00:37Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Christoff](https://avatars.discourse-cdn.com/v4/letter/c/dec6dc/32.png) [@Christoff](https://discourse.nodered.org/u/Christoff)
#### Post date: [3 August 2021 17:00 UTC](https://discourse.nodered.org/t/combining-strings-referencing-csv-and-picking-a-specific-value-based-on-a-global-value/49276/1 "2021-08-03T17:00:37Z")

</div>

Hi,  
I'm trying to put a string together to send to google sheets as a msg.cell.  
I've got return from google sheets working and I can use a inject node to pick and choose cells to get.  
I'm trying to automate it now and I've got two values: msg.currentitem and msg.plusthree  
I want to take those two values and combine them like this Sheet1!A(msg.currentitem):E(msg.plusthree)

I tried the string node and appending it but getting a undefined error in my debug node for the section where I'm referencing the msg items. Also tried a basic function and it gives me the same error. Also at the moment the string node gets triggered twice giving me the following output:

8/3/2021, 6:59:26 PM[node: 1710a041f88e2705](http://localhost:1880/?#)msg.cells : string[25]

"BTC!Aundefined:Eundefined"

8/3/2021, 6:59:26 PM[node: 1710a041f88e2705](http://localhost:1880/?#)msg.cells : string[18]

"BTC!Aundefined:E20"

Any other nodes I can try to stitch it together into one command?  
Thanks in advance for any advice

---

<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: [3 August 2021 17:19 UTC](https://discourse.nodered.org/t/combining-strings-referencing-csv-and-picking-a-specific-value-based-on-a-global-value/49276/2 "2021-08-03T17:19:56Z")

</div>

Maybe the template node ?

---

<div class="post-metadata">

### Author: ![Christoff](https://avatars.discourse-cdn.com/v4/letter/c/dec6dc/32.png) [@Christoff](https://discourse.nodered.org/u/Christoff)
#### Post date: [4 August 2021 07:49 UTC](https://discourse.nodered.org/t/combining-strings-referencing-csv-and-picking-a-specific-value-based-on-a-global-value/49276/3 "2021-08-04T07:49:59Z")

</div>

How would I use two different incoming msg payloads then as part of the formatting? Tried: `BTC!A{{msg.currentitem}}:E{{msg.plusthree}}`  
But it prints it without the messages. Also it still activates twice cause the two values are calculated separately.

I think a function might be a better node to use. I just have no experience with using it or the syntax. The idea is gets a number read in from a csv. Then it needs to stitch the following together:  
BTC!A(csv number):E(csv number + 3)

---

<div class="post-metadata">

### Author: ![Christoff](https://avatars.discourse-cdn.com/v4/letter/c/dec6dc/32.png) [@Christoff](https://discourse.nodered.org/u/Christoff)
#### Post date: [4 August 2021 08:04 UTC](https://discourse.nodered.org/t/combining-strings-referencing-csv-and-picking-a-specific-value-based-on-a-global-value/49276/4 "2021-08-04T08:04:38Z")

</div>

![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/9/e9e5e3819f27836ee30fef4c9838f0177e754cbb.png)  
Here's my current flow. The section bottom left is what I'm trying to replace with a function now

---

<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: [4 August 2021 08:12 UTC](https://discourse.nodered.org/t/combining-strings-referencing-csv-and-picking-a-specific-value-based-on-a-global-value/49276/5 "2021-08-04T08:12:03Z")

</div>

Messages will never arrive from 2 places into the same node at the same time. Never.

So you need to either store values in context (then retrieve them) or use something like the join node.

See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

---

<div class="post-metadata">

### Author: ![Christoff](https://avatars.discourse-cdn.com/v4/letter/c/dec6dc/32.png) [@Christoff](https://discourse.nodered.org/u/Christoff)
#### Post date: [4 August 2021 08:17 UTC](https://discourse.nodered.org/t/combining-strings-referencing-csv-and-picking-a-specific-value-based-on-a-global-value/49276/6 "2021-08-04T08:17:46Z")

</div>

If I can figure out how to do the function node I won't have two messages to join together. Just using nodes to do basic math and then combining it again at the moment.

---

<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: [4 August 2021 08:28 UTC](https://discourse.nodered.org/t/combining-strings-referencing-csv-and-picking-a-specific-value-based-on-a-global-value/49276/7 "2021-08-04T08:28:51Z")

</div>

Then don't branch flows as that creates multiple messages. Wire in nodes series and store the values in different part of `msg` so as not to overwrite previous values.

Lastly, see the node-red docs regarding writing functions and using context.

Ps,

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour.

There a few gems in that playlist ☝ that will help it all just "click" for you. for example, the copy path button on the debug output.

---

<div class="post-metadata">

### Author: ![Christoff](https://avatars.discourse-cdn.com/v4/letter/c/dec6dc/32.png) [@Christoff](https://discourse.nodered.org/u/Christoff)
#### Post date: [4 August 2021 13:10 UTC](https://discourse.nodered.org/t/combining-strings-referencing-csv-and-picking-a-specific-value-based-on-a-global-value/49276/8 "2021-08-04T13:10:21Z")

</div>

Refactored most of my flows now based off that playlist. Also changed things around to now periodically update from the google sheets but also store a local csv. The thing I'm struggling with now is referencing a certain value from the csv as it's a big array(?) of data. Basically I want to go and reference a certain col and then a amount that I've set to a global value but not having any luck with change nodes and understanding how I'm going to filter it.

---

<div class="post-metadata">

### Author: ![Christoff](https://avatars.discourse-cdn.com/v4/letter/c/dec6dc/32.png) [@Christoff](https://discourse.nodered.org/u/Christoff)
#### Post date: [4 August 2021 13:27 UTC](https://discourse.nodered.org/t/combining-strings-referencing-csv-and-picking-a-specific-value-based-on-a-global-value/49276/9 "2021-08-04T13:27:31Z")

</div>

![Screenshot_6](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/f/2fa397903f55de27759d48593a4f1bc90a00263e.png)  
 ![Screenshot_9](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/abe5d8b60718116d63a49df4c785d8f962f25f8a.png)

The last one is where I'm stuck now. Basically just need to get a value from col 4 and a row that's referenced by a global value.  
I've put all of my tcp connections on a separate flow to prevent them from constantly reconnecting whenever I deploy changes.

---

<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: [3 October 2021 13:28 UTC](https://discourse.nodered.org/t/combining-strings-referencing-csv-and-picking-a-specific-value-based-on-a-global-value/49276/10 "2021-10-03T13:28:20Z")

</div>

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