Trying to make a loop to automatically populate some database fields. The following async wixData.update() works:
wixData.query('database')
.find()
.then((results) => {
let items = results.items;
items.forEach((item) => {
item.seoTitle = item.name + item.lengt + item.builder
wixData.update('database', item)
})
})
However, sometimes some fields on some rows go missing (even though I am using the query THEN update). I've been trying to achieve the same thing using getCurrentItem & setFieldValue as follows:
let numOf = $w('#dataset').getTotalCount()
$w('#dataset').getItems(0, numOf).then((results) => {
let items = results.items;
items.forEach((item) => {
$w('#dataset').setFieldValues("seoTitle", item.name + item.length +
item.builder)
$w('#dataset').save()
})
})
But I just can't get it to work. It only writes in the first row only, and doesn't move on to the next item. I've also tried using for loops too, same result.
I'd really appreciate someone pointing out what I'm doing wrong... Thanks.
@givemeawhisky can you help with this?