I’m working with placing objects inside an array that is then being placed in a database. There isn’t much documentation or help I can find on the internet for arrays used as field types, so if there’s anything anyone knows about please tell me! Whenever I use update or save to try to save the array to the item, it gives me this error and I’m not sure what it wants me to do or what’s wrong with it
Error: WDE0004: Failed to save [undefined] into [dbtsAddresses]. Items must be JavaScript objects.
This is my 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;
let toUpdate;
let allServices = [];
wixData.query("dtbsAddresses").eq("_id", id).find()
.then((results) => {
if (results.length > 0) {
allServices.concat(results.items[0].gdServices);
allServices.push(firstService);
console.log(allServices);
toUpdate = {
"_id": id,
"gdServices": allServices
};
console.log(toUpdate);
$w('#inpNotesOnVisit').value = "";
$w('#dtDateOfService').value = new Date();
console.log("done");
}
})
.catch((err) => {
console.log("query: " + err);
});
wixData.update("dbtsAddresses", toUpdate).then((items) => {
let item = items;
}).catch((err) => {
console.log("save: " + err);
});
}
Database:
I’ve been testing on the row with the square brackets in the services field.
Thanks for any help!