I created my own item’s ID field to use it on my web site, instead of Wix complicated id. I activated a beforeInsert hook for my collection, and it works fine with a simple code, like this one, which assigns “5” value to the field:
mport wixData from 'wix-data';
export function Properties_beforeInsert(item, context) {
item.postNumber = 2 + 3;
return item;
}
Now I need to make a bit tricky formula, like { id value = total number of items in a collection + 1 }. I added a query functon but it’s not working - no value is put in a field. Here is my code that doesn’t work:
export function Properties_beforeInsert(item, context) {
wixData.query("Properties")
.find()
.then( (results) => {
item.postNum = results.totalCount + 1;
});
return item;
}
I’m pretty new to code, so can anyone help with this part?