I need to duplicate a record (item) but can’t figure it out. In my case, I need all of the user input fields copied and placed in a new record. There is no copy() or duplicate() examples I can find. I don’t know what else to search. Can someone point me in the right direction?
Background
A user creates a record of data assigned to a meeting date. It is a meeting agenda item. That item needs to stay on its current meeting date and also be added to a new meeting. Therefore, I need all of the user input fields to have their data copied and pasted in a new record where a new meeting date will be assigned. I can isolate the data I want with getCurrentItem, make a new item with add() , but how do I duplicate or copy/paste the data?
I have tried versions of copyToClipboard, get/setCurrentItem, wix-storage, focus(), let and const variables, and scissors and duct tape. I can isolate and print a specific value I am trying to place in one of the new item’s fields in console.log(). So the issue must be with how I am trying to place it into the new item’s blank field. Again, ideally, I just duplicate the current item but if I have to copy paste field by field I can live with that if I could figure how to paste?insert?update?
I am embarrassed that I have to ask for help on copy/paste. But I guess I do. @yisrael-wix can you humor me with your help?
I have only done it using backend code on the actual table (collection).
But, I think you are on the right track with .getCurrentItem().
When you save this, it copies all the fields from current record that the dataset is on, and puts it into a variable.
You can then use .setFieldValues() to put the fields back into a blank page, using the saved fields from the variable you created in the above step.
After putting the fields back, you can then change any field you need, after using the .setFieldValues().
The only issue I can see that might cause you grief is the _id field. This contains a unique GUID, and I’m not sure how the dataset will react when you add() the new information back into the table. I am not sure if it will be ignored, and a new one created, or if you will get an error message indicating that the record already exists. You might have to remove the GUID. You will have to try and see what happens. Let us know.