top of page

Forum Posts

Elliot Grey
Feb 21, 2020
In Coding with Velo
I've been trying for hours to do this and I cannot figure it out. This is something that is so simple to do in nearly any db framework, and I'm constantly hitting a wall... I have a collection of survey info which has a reference field to the users collection. All I want to do is create a form and INPUT the logged in user INTO the survey collections USER reference field. Here is my code: import wixData from 'wix-data'; import wixUsers from 'wix-users'; let currentUser = wixUsers.currentUser; export function button2_click(event) { //Add your code for this event here: let toInsert = { "title": $w("#input1").value, "content": $w("#input1").value, "satisfaction": $w("#input1").value, "user": currentUser.id //THIS IS THE REFERENCE FIELD }; wixData.insert("Survey", toInsert) .then((results) => { let item = results; //see item below console.log(item) }) .catch((err) => { let errorMsg = err; }); } I have even tried hard coding that user value with an id from the user collection and it still does not work. I don't get any errors, the collection updates and the user reference field is blank. I have also tried hard coding values using the insertReference function and that also does NOT work. Any help would greatly be appreciated!
0
8
1k

Elliot Grey

More actions
bottom of page