I am attempting to put multiple objects named Service into an array, and put that array into my dbtsAddresses database in the array field type.
I am adding a function to the database that allows the user to input a new service, each new service would be its own Service object that would be added to the array in the corresponding customer’s record in the database.
I am receiving this error:
WDE0025: The dbtsAddresses collection does not exist. You cannot work with a collection using the Data API before it is created in the Editor.
when running my code and I really don’t know why.
Page Code:
export function btnSubmitNewService_click(event) {
//Add your code for this event here:
let id = $w("#dynamicDataset").getCurrentItem()._id;
let address = $w('#txtAddress').text;
console.log(address);
let date = $w('#dtDateOfService').value;
console.log(date);
let notes = $w('#inpNotesOnVisit').value;
console.log(notes);
let firstService = new Service();
firstService.Address = address;
firstService.Date = date;
firstService.Notes = notes;
console.log(firstService);
let toUpdate;
let allServices = [];
wixData.query("dtbsAddresses").eq("_id", id).find()
.then((results) => {
if (results.length > 0) {
let item = results.items[0];
allServices.concat(item.gdServices);
allServices.push(firstService);
console.log(allServices);
toUpdate = {
"_id": id,
"addAddress": item.addAddress,
"txtAddresses": item.addAddresses,
"dateOfInstall": item.dateOfInstall,
"addCustomer": item.addCustomer,
"phoneNumber": item.phoneNumber,
"emailAddress": item.emailAddress,
"notesOnCustomer": item.notesOnCustomer,
"gdServices": allServices
};
console.log(toUpdate);
$w('#inpNotesOnVisit').value = "";
$w('#dtDateOfService').value = new Date();
console.log("done");
wixData.update("dbtsAddresses", toUpdate).then((items) => {
let test = items;
}).catch((err) => {
console.log("save: " + err);
});
}
})
.catch((err) => {
console.log("query: " + err);
});
}
Service.js code:
import wixData from 'wix-data';
export class Service {
//look at java object files to remeber how work
set Address(txtAddress) {
this.address = txtAddress;
}
get Address () {
return this.address;
}
set Date(date) {
this.dateOfInstall = date;
}
get Date() {
return this.dateOfInstall;
}
set Notes(note) {
this.noteOnVisit = note;
}
get Notes() {
return this.noteOnVisit;
}
}
my website: https://editor.wix.com/html/editor/web/renderer/edit/c3ce1a2e-10be-429f-a16c-f968c015b8c5?metaSiteId=55d3d8d0-a4d9-41ff-95e6-ed0dbd262842&editorSessionId=17c89499-565a-40ad-9352-594694d16ea3&referralInfo=dashboard
on the Addresses (ID) page.
If there’s anything that could be helpful that I’ve forgotten, please tell me and thanks for any help given!