How To Add Records After Querying
Hi, I'm working on an app that needs to show a list of objects (5 meditations) for each week. I query the 5 based on their timestamp which works perfectly. This 5 will change every week and I want to update a table that holds the current list. (Im doing this because simply querying them returns nothing on the weekends)
I have a function stack that will run once a week and update the meditations by deleting what is there, querying the new records for the current week, and adding the new records. I have the delete and the query working, but I cant figure out how to add the new records.
The bulk add is useless the way I understand it because it doesnt allow me to map fields. So I'm looking at adding them 1 by 1. It's only 5 so it shouldn't be too bad.
When I'm adding a new record, how can I reference the id of the first object in the variable that contains the queried objects? and the second, and the third etc. I understand dot notation but I'm not sure how to reference specific objects in an array.
Answers
-
You have two options to access an object property from a list of objects.
A) The brute force way. It could be acceptable in your case because you have only 5 records to add.
meditation_1.0.id
meditation_1.1.id
meditation_1.2.id
meditation_1.3.id
meditation_1.4.id
This is brute force because you have to hard code them as is, and you can't use the
sprintf
filter to iterate in a loop. Basically, doingmeditation_1.%d.id sprintf index
won't work.B) The elegant way.
Use the
get
filter on an array to access its items by their index. Use theFor Loop
function to get access to theindex
variable and run it for arraycount
times. Then access the id property like so:meditation_1 get index get id
.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback