Hello,
I’m rather new to this, and I am trying to create a button that automatically takes the selected field in a dataset, and the current user, and inputs both of those into fields in a separate dataset.
Specifically, I have dynamic pages, and I want the user to be put into a database associating themselves with given pages. So I need to grab the specific entry that the page is based off, and who the user is, and put that into a collection.
Can someone give me some ideas for how best to do that?
Thanks
You can look at using the Wix Dataset API
So you get the selected fields from a dataset simply by using getCurrentItem.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#getCurrentItem
Then simply use setFieldValue or setFieldValues and save to add it to your other dataset.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFieldValue
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFieldValues
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#save
If your user is a logged in site member, then you can easily get their userID through using Wix Users API and the currentUser function.
https://www.wix.com/corvid/reference/wix-users.html#currentUser
So, in theory you can have the userID set up as a read only user input or have it setup as hidden and then simply have that input added to the setFieldValues part of your code so that it is saved into your other dataset.
Finally, you can also use the Wix Location API and look at using the url or query functions of that too and add that to your dataset.
https://www.wix.com/corvid/reference/wix-location.html