I am just starting out with Node-Red and need some help.. here is what I have so far:
A timestamp inject connected to an http in node which gets a URL API from my baserow site. (the "Return" dropdown is set to "a parsed JSON object".
Connected to the http in node is a debug showing the results..
The above works fine, I see the JSON data come in.
Now I'd like to send the results to a table and here is where I struggle..
I've tried adding a function node to my http in and then to a table.. In that function node, I tried a "for" loop to add the items in the table in turn but no matter what I've tried thus far, only 1 value shows up in the table..
Here is the code I've tried:
for (let index = 0; index < msg.payload.count; index++) {
msg.payload = [
{
"Name":msg.payload.results[index].Customer
}
]
node.send(msg);
}
In the above, I basically want one column, Name, with the customer populating in the table.. there should be 32 entries but I only ever get the first entry in the table.. I assumed the "for" loop would go through the JSON objects in turn with the index counter and spit the results out to the table..
A few things
I think you mean a http request node not an in node.
There is no count property of an array, i think you mean length.
What does your incoming payload look like.
You are overwriting the payload you are iterating through.
When you say table what exactly do you mean.
Thanks for your reply.. Yes as I'm learning node-red, I'm bound to get some terminology incorrect..
The incoming payload looks like the following.. this is only part of it.. there's 32 entries of this stuff..
1: object
id: 4
order: "4.00000000000000000000"
Customer: "Camis"
Description: "Supply & install cellular amplifier system at Sibbald PPK; Park store location."
Technician: array[1]
Status: array[1]
Date added: "2022-08-18"
Service Order: "WO-016019"
Invoiced: true
Job Name: "Cell amplifier at Sibbald PPK."
So essentially I want to grab the customer from each entry and have in a dashboard table..
Table would look like:
Customer
CAMIS
CUSTOMER 2
CUSTOMER 3
CUSTOMER 4
...and so on so forth until count ends..
I'm using an index variable as the number of entries (currently 32) could vary..
If I'm overwriting the payload I'm iterating through, how do I avoid this? Have the iteration save to a variable array, then put it to table?
Again table has so many meanings, Html( page or ui-template), ui-table, tabulator, and many other dashboard, or you may mean a csv or excel.
The payload does not look like that, it is formatted. To copy it correctly use the debug side panel, if you hover the mouse to right of property name (payload) some icons will appear, one of them is copy value. These icon are very useful including copy path.