How to insert data into collection using code?

Hi! Here is details of the whole issue, and I haven’t received any answers to this.

What’s happening now?
A form with different input fields will take user’s inputs. Two fields from the form will take numbers from the user.
In the code, calculation will be done using these two input as variables - for example input1 * input2 = result
The result will be stored in a column in the collection previously created called “total” .

What’s the problem?
The result I get after performing the calculation is 0 and it automatically gets stored as new entry in a new entry. So, the form submitted will have all the inputs users entered in one row, and the calculation result in another row. I’m not sure why, or how to reference the same _id that will be submitted. I don’t the _id yet so it’s difficult to implement it.

What I’m trying to achieve?
I want to be able to store more data in different columns, as well as a custom generated ID on form submission. The user doesn’t have to be registered or anything. Just a regular form submission.

What component I have right now?
I have a page with simple form connected to a dataset that writes to the collection using the dataset, and the code below. I also have collection with different columns (see screenshot below), and finally a piece of code to perform the calculation and insert them on submission.

Here is the code used


The function calculates the price (user’s input) and cbm(user’s input) and finally return the result as “customerPrice”

The second function to insert data

Finally the function to generate custom ID

my collection id: snapchat-collection
dataset Id: snapchatwrite

Screenshot of the collection

Screenshot of the form

Please let me know if you have any questions. Thank you very much!

My guess would be to unhook the submit button from the dataset and save() your form entries. Then use wixData.get to retrieve the item, make edits and wixData.update to store in the collection. My apologies in advance if I misunderstood the problem…