We are trying to import records into Corvid Data base. We are able to get records to import but have been unable to use the Save function only insert. If we are only able to use insert we need to be able to clear out the data base before the insert occurs. If we are able to clear out the data base and then import our records everything works correctly. Can someone please help me understand how to fix the save function or the clear function? When we try and run our flow to import records it seems to time out. Thank You!
‘use strict’; import wixData from ‘wix-data’; import {ok,response} from ‘wix-http-functions’;
export function post_storerecords(request){
clearCollection();
If you want to completely clear out records and overwrite everything, then you would be far better off using wixData.update() ? Then you don’t need to worry about insert or save…
wixData.query("databaseImport") // From the database you want to import from
.find()
.then((results) => {
let items = results.items;
items.forEach((item) => {
wixData.update("databaseWrite", item) // The database you want to write to
})
})
N.B. I don’t think this applies to you (since you appear to be updating all fields) but "when updating an item in a collection, all existing item properties must be passed to the update() function. If only the changed property is passed, the values of the other item properties will be lost. To ensure all item properties are included in the update, perform a query() on the item, change a property, and then update() the item. "
I’m not sure if Update will work for us. Basically, we are using a google sheet and then microsoft flow builder on a time trigger to pull the information from google sheets and then having it upload into our database with wix. We need it so that when a new user is added on that google sheet it will update the wix database to allow the user to gain access to a form. Or if a users status on our google sheet is changed to inactive we need that to be able to be updated as well in the wix database. So we either have to be able to use the WixData.save function or we need to be able to use a clear function and then insert.
@shannonfoster I might be wrong, but I can’t see why it wouldn’t work. Instead of your line
return wixData.insert(“AgentInfo”, recordInsert)
have instead
wixData.update(“AgentInfo”, recordInsert)
Assuming that there are no other fields than “title”, “_id”, and “active” (otherwise any other fields will be lost). But even if there are others you can just query the individual record first, and THEN do the update, and then no referenced fields won’t be lost. Anyway I’d prefer to do the update inside a query.then