Why am I getting this error in the collection?

My code:
let weekHourArray = [
{mondayMorningOpen: "morningOpen", mondayMorningClose: "morningClose", mondayAfternoonOpen: "afternoonClose", mondayAfternoonClose: "afternoonClose"},
{tuesdayMorningOpen: "morningOpen", tuesdayClose: "morningClose", tuesdayAfternoonOpen: "afternoonClose", tuesdayAfternoonClose: "afternoonClose"},
{weddayMorningOpen: "morningOpen", weddayMorningClose: "morningClose", weddayAfternoonOpen: "afternoonClose", weddayAfternoonClose: "afternoonClose"},
{thursdayMorningOpen: "morningOpen", thursdayMorningClose: "morningClose", thursdayAfternoonOpen: "afternoonClose", thursdayAfternoonClose: "afternoonClose"},
{fridayMorningOpen: "morningOpen", fridayMorningClose: "morningClose", fridayAfternoonOpen: "afternoonClose", fridayAfternoonClose: "afternoonClose"},
{satdayMorningOpen: "morningOpen", satdayMorningClose: "morningClose", satdayAfternoonOpen: "afternoonClose", satdayAfternoonClose: "afternoonClose"},
{sundayMorningOpen: "morningOpen", sundayMorningClose: "morningClose", sundayAfternoonOpen: "afternoonClose", sundayAfternoonClose: "afternoonClose"},
]
export function openingsHoursSaveButton_click(event) {
$w("#datiNegozioDataset").onReady( () => {
$w("#datiNegozioDataset").setFieldValue("openingsHours", weekHourArray);
$w("#datiNegozioDataset").save()
console.log("Saved")
});
}
Any suggestions? Thanks in advance!
Perhaps this one? (NOT TESTED!)
$w.onReady(function () {
$w('#button1').onClick(()=>{
$w("#dataset1").onReady(() => {
let weekHourArray = [
{mondayMorningOpen: "morningOpen", mondayMorningClose: "morningClose", mondayAfternoonOpen: "afternoonClose", mondayAfternoonClose: "afternoonClose"},
{tuesdayMorningOpen: "morningOpen", tuesdayClose: "morningClose", tuesdayAfternoonOpen: "afternoonClose", tuesdayAfternoonClose: "afternoonClose"},
{weddayMorningOpen: "morningOpen", weddayMorningClose: "morningClose", weddayAfternoonOpen: "afternoonClose", weddayAfternoonClose: "afternoonClose"},
{thursdayMorningOpen: "morningOpen", thursdayMorningClose: "morningClose", thursdayAfternoonOpen: "afternoonClose", thursdayAfternoonClose: "afternoonClose"},
{fridayMorningOpen: "morningOpen", fridayMorningClose: "morningClose", fridayAfternoonOpen: "afternoonClose", fridayAfternoonClose: "afternoonClose"},
{satdayMorningOpen: "morningOpen", satdayMorningClose: "morningClose", satdayAfternoonOpen: "afternoonClose", satdayAfternoonClose: "afternoonClose"},
{sundayMorningOpen: "morningOpen", sundayMorningClose: "morningClose", sundayAfternoonOpen: "afternoonClose", sundayAfternoonClose: "afternoonClose"},
]
$w("#dataset1").setFieldValue("openingsHours", weekHourArray);
$w("#dataset1").save()
console.log("Saved")
})
})
})
Checked all database-permissions?
Yes, all database-permission at the moment are set to “all”
It doesn’t seem to pass the setFieldValue function
Can not do it from here, can take alook if you want. Contact in my profile.
I solved the issue with the setFieldValue. But the original error in the collection still remain…
What was the failure, which you could solve? What did you change?
How looks like your new code?
the setFielValue function did not work because some mandatory fields were empty (I hadn’t noticed the error because I have so many fields and some were hidden).
I also solved the original problem (error shown in the collection). Instead of using the setFielValue(), I now use a get and then an update query. Something like this:
wixData.get("myCollection", itemId)
.then((toInsert) => {
toInsert.openingHours = [
mon1,mon2,mon3,mon4,
tus1,tus2,tus3,tus4,
wed1,wed2,wed3,wed4,
thu1,thu2,thu3,thu4,
fri1,fri2,fri3,fri4,
sat1,sat2,sat3,sat4,
sun1,sun2,sun3,sun4
];
wixData.update("myCollection", toInsert)
.then((result) => {
console.log(result);
$w("#openingHoursDataset").save()
.then (() => {
$w("#savingOpeningHoursGif").collapse();
$w("#openingHoursStatusText").text = "Saved"
$w("#openingHoursStatusText").expand();
setTimeout(function() {
$w("#openingHoursStatusText").collapse();
$w("#openingHoursStatusText").text = ""
}, 4000);
})
})
.catch((err) => {
...
});
})
.catch((err) => {
...
});