Select value from CSV file

I made a product selector in node-red dashboard where I can select 3 different products from a csv file.
The csv file includes a 'takt' value with is corresponding to the product. (column B in csv file)

Product selector:


Schermafbeelding 2021-05-02 om 16.29.13

I want to use de corresponding 'takt' value from the csv in my flow as well. I searched a lot but I didn't find the right method to do this.

Can anyone help me with the right method?

So I don't need to see the value in my dropdown menu. I only need to use the takt value witch belongs to the selected product.

Use a change node to move the values from the csv to make an array of product names and value. i.e.

[{"id":"fde8f8.31889708","type":"inject","z":"9b3f9f31.c45298","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":1780,"wires":[["5e502573.725154"]]},{"id":"5e502573.725154","type":"template","z":"9b3f9f31.c45298","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"product,takt\nball,20\ntrain,30\nhat,60","output":"str","x":130,"y":1860,"wires":[["c601359c.1c0a38"]]},{"id":"c601359c.1c0a38","type":"csv","z":"9b3f9f31.c45298","name":"","sep":",","hdrin":true,"hdrout":"none","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":250,"y":1900,"wires":[["f6354306.6d98c8"]]},{"id":"f6354306.6d98c8","type":"change","z":"9b3f9f31.c45298","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"payload.{product: takt}","tot":"jsonata"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":1900,"wires":[["309c8b52.68564c","d86c7482.e5bc68"]]},{"id":"309c8b52.68564c","type":"ui_dropdown","z":"9b3f9f31.c45298","name":"","label":"test","tooltip":"","place":"Select option","group":"8b5cde76.edd58","order":4,"width":0,"height":0,"passthru":false,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"topic","topicType":"msg","x":650,"y":1900,"wires":[["d86c7482.e5bc68"]]},{"id":"d86c7482.e5bc68","type":"debug","z":"9b3f9f31.c45298","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"options","targetType":"msg","statusVal":"","statusType":"auto","x":700,"y":1800,"wires":[]},{"id":"8b5cde76.edd58","type":"ui_group","name":"","tab":"8f03e639.85956","order":1,"disp":true,"width":"6","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

[edit added delete payload and to show options in debug]

Yes, but how can I select the corresponding value?

Out of the dropdown node comes the product name. How can I use this to select the corresponding takt value from the csv?

If you select ball the drop down output will be 20, the value. If this is not what you want you will need to explain more.

[edit if you want the whole product object you could use

payload.{product: $}

which when you select ball will output

{"product":"ball","takt":20}

]

If I select product “ball” the only value what comes out of de dropdown node is “ball”.
The takt value didn’t go true the dropdown node.

I thought I can use value “ball” (what comes out of the dropdown node) in a separate flow to grab the “takt” value out of the csv file. But I don’t know how...

Here is the screnshot of the output if ball is selected.

Yes, great!

Can you send me the flow please?
And do you have a screenshot of the dashboard where you select “ball”?

it's in post 2.

Thank you @E1cid !!
That’s what I need. :grinning:

But I don’t understand how there only a number comes out with the msg.payload. And not the name “ball” ore something. Where is it managed that only the number value is selected?
Can you explain this to me?

The option array created in the change node contains the key value objects for each entry. The key is the label and the value is what is returned

I think I understand it now. Thank you very much!

@E1cid
Now return the value out of the dropdown node.
I'm puzzling how to return the label and the value out of the dropdown node... can you help me a little further?

Post 4 contains the info you require.

Actually when I do this the payload is nothing:


Schermafbeelding 2021-05-05 om 18.39.45

You give no info that can help. Whats the the input to the dropdown
As it works for me no issues.
Using exact same flow just the change from takt to $ in the change node.

Here is my flow:

[{"id":"97c89a5e.34694","type":"inject","z":"b4370c04.a6c7d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":1520,"wires":[["67700f80.1bdd"]]},{"id":"67700f80.1bdd","type":"template","z":"b4370c04.a6c7d","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"product,takt\nball,20\ntrain,30\nhat,60","output":"str","x":360,"y":1580,"wires":[["c0e5b5dc.9fe7b"]]},{"id":"c0e5b5dc.9fe7b","type":"csv","z":"b4370c04.a6c7d","name":"","sep":",","hdrin":true,"hdrout":"none","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":400,"y":1640,"wires":[["63d7a04d.fd528"]]},{"id":"63d7a04d.fd528","type":"change","z":"b4370c04.a6c7d","name":"","rules":[{"t":"set","p":"options","pt":"msg","to":"payload.{product: $}","tot":"jsonata"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":1640,"wires":[["b72e9cd3.3baa58","bc09b5df.ea4a5"]]},{"id":"b72e9cd3.3baa58","type":"ui_dropdown","z":"b4370c04.a6c7d","name":"","label":"test","tooltip":"","place":"Select option","group":"a21aeffd.644dc8","order":4,"width":0,"height":0,"passthru":false,"multiple":false,"options":[{"label":"","value":"","type":"str"}],"payload":"","topic":"topic","x":800,"y":1640,"wires":[["bc09b5df.ea4a5"]]},{"id":"bc09b5df.ea4a5","type":"debug","z":"b4370c04.a6c7d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":1560,"wires":[]},{"id":"a21aeffd.644dc8","type":"ui_group","name":"Group 2","tab":"80b00f09.0a7c7","order":2,"disp":true,"width":6},{"id":"80b00f09.0a7c7","type":"ui_tab","z":"","name":"Products","icon":"dashboard","order":4,"disabled":false,"hidden":false}]

When I select "ball" in the dashboard. Nothing comes out. :thinking:

Edit: This is the original flow I got from you, the only thing I changed is: payload.{product: $}
As you described in post 4

Did you go to the dashboard product tab and select a item from the dropdown?

The first payload in empty as it is deleted and it is the debug after the change node. The second debug is after ball is selected from the dropdown.

Yes, but I get different result than you have:
The first payload is undefined. (result the same as you have)
The second payload is "" (different result)

Update: I selected the item "ball" (and the result is "")

Strange, Do you have another drop down from another test, are you selecting the correct dropdown?

If you put a debug after csv node what do you get?

if you remove the delete payload from the change node, and sset the debug to show complete message, what do you get?

[edit]
Thats the home group, the flow you sent me is products

I deleted the first flow, this was in products tab of the dashboard.
The second flow is in the Home tab.
I only use the home tab now.

This is what I get when I don't delete the msg.payload.
The first message is when I hit the inject node.
The second message is when I select "ball" in the Home tab.