The Easiest Way to Edit/Create a Record
Options
![Oliver Burrell](https://us.v-cdn.net/6037124/user_avatars/1677616.jpg)
Oliver Burrell
Member ✭
What's the easiest way to create an API if I need to edit a record if it exists or add a new one if it doesn't.
I thought of querying all records for a match of the searched columns (other than the id) and if found I return the id in a variable.
If the id is not null I edit the record and else I add a new record.
I tried to do that but I can't get it to work.
Xano complains that it can't see the [variable name].id field.
I thought of querying all records for a match of the searched columns (other than the id) and if found I return the id in a variable.
If the id is not null I edit the record and else I add a new record.
I tried to do that but I can't get it to work.
Xano complains that it can't see the [variable name].id field.
Comments
-
Hi Oliver - there is a function that does this. You will want use the Add or Edit Record function (Function Stack > Database Requests > Add or Edit Record).
This will do a record lookup based on the field you define, if it finds the record exists then it will edit it, if it doesn't exist then it will add a new record. -
Hi Michael, thanks but I can't find this function.
After I click 'Add API Endpoint' I get the following options:
[Screenshot 2021-08-12 at 21.32.26.png]If I then click CRUD I can't see Add or Edit Record ...
Where do you mean? -
In the Function Stack (when you add a new Function). Not a new API Endpoint.
[Screenshot_2021-08-12_20-42-22.png] -
I never looked that far down
cheers!
-
Hi Michael, What do you do if you have two columns to find the record by? I need to search using the fields users_id and procategories_id instead of the id field.[Screenshot 2021-08-13 at 11.07.58.png]
-
Did you get this sorted? I'm curious on this myself.
-
Use a query all records function to search with the multiple constraints and change your return type to single. Then you can pull the id field from the result variable
-
, yes, it works if you query all records and then you can select by multiple fields and the result needs to go into a variable. Please see the example below ...
[Screenshot 2021-11-16 at 09.41.34.png][Screenshot 2021-11-16 at 09.41.49.png]
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