I am trying to add an after Insert hook that queries a second database, if the query finds there is already an entry in that database that matches the query it will do nothing, if it finds there is no entry it will insert information into that database. Does anyone have any pointers as I can’t figure out how to make this work. Here is the code I am starting with:
wixData.query("stallBlocks") //search second database to see if phone number //is already in there
.eq(`item.trainerCellPhone`: `item.trainerCellPhone`)
.eq(`item.horseShowId`:`item.horseShowId`)
.limit(1000)
.find()
.then((results) => {
let firstItem = results.items[0]
if (results.totalCount === 0) {
//here is where I insert the trainer cell phone into the second //database
}
I want it search based on the last item inserted so after it is inserted, it searches the other database, and if it doesn’t match those two parameters it inserts a new item. Is this possible?