Is it possible to set up a new field so that the first customer who fills in the form to be “1”, the second as “2”, etc.
Since I am still new to the use of hooks, I do not understand why I could not get the results I want with the below code, which is a replicate from a relevant post.
import wixData from 'wix-data';
export function Database_beforeInsert(item, context) { // item contains the inputFields from the form
return wixData.query("Database")
.limit(1)
.descending('field') // descending() sorts the results in descending order by property, i choose "field"
.find()
.then((results) => {
const lastItemInCollection = results.items[0];
item._id = `${Number(lastItemInCollection._id) + 1}`;
return item; // beforeInsert function returns the item
});
}