i have a website in wix which people submit via a form, the data from the form goes to a database collection called royaldynasty. i want that before the data enter the collection i can change it a littel, so i used the beforinsert() function, what i want to do is to take tha highest value from a coulmn called fortune in the collection called royaldynasty , and add 1 to it and return the new value to the fortune coulmn in the new user row. i tried using get or fint but i dont know sql very good so i didn’t understood how to use the get() or find().
i will love if someone will show me how to write the code and explain me so in the futuer i will know to write it by myself.
thanks from advance, and sorry for the bad english :).
Hi Dor,
As far as I understand your question you should use query inside the hook, the query will find the highest value in the column fortune, then you should add 1 to the value and update the value to your new user row.
The following articles should explain exactly how to write this code:
Good luck
i read the articals and tried it in my website, i does not work.
this is my beforinsert() code. what i did wrong?
Hi Dor,
Seems like you’re doing the change upon reading the data (after using ‘query’) and you don’t update the data back to the database. Also, seems like you’ve set the hook to be ‘afterInset’ and not ‘beforeInsert()’.
Please follow example here .
Liran.
hi Liran,
why i need to use the update() when i am returning the new items in the end with the return() function?