Looping through DB rows

Hello friends,

I am thinking of making a workflow for Google Docs for each value in DB. Let’s clear this up with an example. We have something like this in our DB.

DB data:
merchant_id, goods, actual_sell, expected_sell
1, bread, 34, 100
1, oil, 54, 100
1, chair, 12, 100
2, medicine, 40, 100
2, towel, 23, 100
2, fruits, 89, 100

we have defined templated with variable name inside it as per the different merchant_id. Now, we want to make a report of selling based on merchant_id. If merchant_id = 1 then grap the details of it and also DB_2 contains the further related details of merchant_id 1.

If merchant_id = 2 then grap the details of it and also DB_3 contains the further related details of merchant_id 2 and so on.

So, now, can I create the workflow that will go through each row in DB? If the merchant ID comes first, then copy the Google Doc with that merchant ID that contains the variable and insert the details of DB, DB_2, DB_3, etc. based on variable name defile in google doc node.

Final result will be 1 google doc for each merchant_id with related details.

My current workflow without loop. (With this I need this flow for each merchant_id which is too much )

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @Lucifer ,

Not sure if I’ve fully understood your question, but have you considered joining the different databases so that you have a new database, each row containing all the information needed to create a report per goods with a specific merchant_id including details from other databases? Then, you can simply generate a Google doc for each row of that new db?

Tip for sharing your workflow in the forum

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

Make sure that you’ve removed any sensitive information from your workflow and include dummy data or pinned data as much as you can!


Hey @aya,

The final report contain multiple data that needs to grep from the different DB with different schema (Indoor items, Outdoor items and Both). Now, for each merchant_id, we need 1 separate report. Currently, we are multiplying the snapshot architecture for x number of merchants. If we can add condition like if merchant_id is 1 then take the related merchant_id template (with variable), copy it, run query_1(Indoor item), query_2(Outdoor item), query_3(Both) and place it on google doc in the place of variable that define in template related to merchant = 1 report. Same goes to merchant 2, 3, 4 etc.

If merchant_id changes; templates with variable changes, query_1/2 and query_3 change.

I hope I can explain in a better way. Let me know, if you are still in any doubt.

Thanks

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