Easy Way To Repeat Code For Multiple Rows Of Data (To Assist With Search Bar)

Hi all,

I’ve made a couple of threads recently about needing help with creating a search bar and adding data to my project from a Google Sheet. After a week of reading multiple Community threads for help, watching videos and some blind trial and error, I believe I’ve finally made progress.

But I need help with the next section, which is to repeat my code without having to manually input code for each row. Let me explain with as much detail as I can…

So in my app, there’s a marketplace to trade Pokemon Cards. When you load the ‘Trading Market’ page this is what you are met with (pictures are just placeholders for now).

The following code is executed…

The local table/database is completely wiped clean of any lingering info (this may not be necessary, but I was having some issues without it so I put it in there for peace of mind). The first ‘Default’ Data Grid is refreshed, which is directly linked to the corresponding Google Sheet. It is then made visible and the second ‘Filtered’ Data Grid is made invisible.

The Google Sheets API/CSV is then called, with the usual Parsing data magic that occurs.
image

After this, I’ve had the page create a new row in the Local table/Database. It then updates the specific columns and rows based on the API/CSV data. Now, before I couldn’t get it to do this until I asked it to ‘get value’ from the Google Sheets document directly.


I have also set this up for the second row…

The final part is when a user types in their “Search” in the ‘Search Bar’ and ‘Clicks’ the ‘Search Button’ it activates the below code to identify if the row has the used phrase or not.

image

If the phrase matches the row data, the row remains in place…

If the phrase doesn’t match the row data, the row is deleted…

This part is unrelated, but when a user clicks the item, it takes them to another screen which will contain all of the info and options…

Now what I need help with is finding a way to loop this action for every row that could contain data. At the moment, I only know how to proceed by manually writing out this sequence for every row of data. It’s not ideal, but it can be done to an extent, but I anticipate it would be a HUGE amount of code (especially if the number of listings reaches the hundreds) and I wanted to know if anyone has any idea on how to make this smaller and more dynamic, so I don’t need to manually ask it to pull in data for every row.

I’m sure I will get some comments about some of the unnecessary code in this, but I’ve played around with a lot of stuff in the past week and had no success and this is the first time I’ve made this breakthrough so I’m super stoked - so if anyone does have any suggestions for limiting the amount of code/blocks I’m happy to take it on board :slight_smile:

Any help is greatly appreciated!

TLDR - I need help repeating code for multiple rows of a Google Sheets doc rather than manually typing them all out!

Hello @8bitretrofishep
Thank you for sharing all the details and screenshots.
Since you have connected the data viewer grid with the Google sheet, you don’t need any blocks when screen opens.
When button click you can use the following blocks:

1 Like

Hi there, really appreciate the reply.

I tried to implement this and it wasn’t successful, it only produced an empty screen. I did this both with the first part of the existing code as it was, I tried meshing the codes together and also tried clearing all of the code.

I’m also not sure where the looping comes into effect in your example. The code I have created works for single rows, but I want it to automatically replicate this code for all other rows.

I essentially need the rowid value ‘1’ in the ‘get value from Trading Card Tracker Trade Market Data’ block to change to ‘2’, ‘3’, ‘4’ etc. without having to put the blocks in manually.

The blocks in that screenshot are almost correct. Replace app variable Card Details Google Sheet Row with app variable rowdata. If that doesn’t work, post a link to your project and someone can let you know what needs to be changed.

Still no success, it just brings up a blank grid when I type into the search bar.

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