Hello,
I had a look through your video on creating a todo app.
Now that I have a bunch of records, I’d like to delete the ones marked as “done”. How can this be achieved? I have created a “Delete Done Tasks” button and I’m trying to utilize the “Delete Record” logic.
I have troubles deleting even a single record without hardcoding the ID as I’m not sure how to find the correct ID corresponding to the task name. What would happen if there are multiple tasks with the same name?
Thanks for you assistance upfront!
For deleting one record, I got around by using “tap component” on the list and storing that as a data variable. Then I click the “Delete Done Tasks” button and it works. Not the prettiest way of doing it but at least something.
How could I still achieve deleting multiple records?
I’m probably using a different database (Firestore), but the basic principle is that you would create a logic loop. You have a couple of format options, but since reads in Firestore are insanely cheap, I would do it this way:
- Get All Records (tasks)
- Set a data variable equal to the subset marked “done” (use SELECT function)
- If the data variable’s list length is 0, then you’ve deleted all the “done” tasks, so you can move on (end loop). Otherwise:
- Set a page variable equal to the ID of the first item in the data variable.
- Delete, using the ID you’ve set. Loop back to…
- Get All Records (tasks)
1 Like
If you want to minimize calls to the database, you can also just do a single Get All Records, and create an “increment” variable that you will set equal to the number of items in the data variable (list) that you created in Step 2. Then at the end of each loop you subtract one from the “increment” variable, and Step 1 in the loops is just to check whether the increment variable = 0, in which case, end the loop.
1 Like