I want to set two values for my database record. One value is the field itemId is the number of record of of the database , and the second fields is to set the as “0”.
I used the afterInsert callback:
export function donated_items_afterInsert(item, context) {
let numOfResults;
wixData.query( “donated_items” ).find().then((results) => {
numOfResults= results.totalCount;
});
wixData.get( "donated_items" , item._id).then((toUpdate) => {
toUpdate.itemNumber = Number(numOfResults);
toUpdate.doneeId = "0" ;
wixData.update( "donated_items" , toUpdate);
})
}
But I got the following errors during insertion:
Hook afterInsert for collection donated_items result ignored! Expected hook result to resolve to an object with an ‘_id’ property, but got [Undefined]
My questions are:
- is there a better way to do this?
- what is wrong with the _id? I just update the same item just inserted.
Thanks!
Hugo