I have two datacollaections. one is users and another one is for books. I would like to copy the bookID field content from the book datacollection to the booknumber into the user datacollection when pressing a button or other way when submitting a form.
top of page
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
bottom of page
Hi,
You can use queries, update and insert. create an onClick event for the submit button, use query to get the user you want to update, then update it with the BookID and finally insert the data from the form.
The code should basically look like this:
export function submitBtn_click(event) { let data = $w("#text1").text; let bookID = $w("#text2").text; wixData.query("users") .find() .then((results) => { let toUpdate = { "_id": results.items[0], "bookNumber": bookID }; wixData.update("users", toUpdate) .then((results) => {}) .catch((err) => { let errorMsg = err; }); }) .catch((err) => { let errorMsg = err; }); let toInsert = { "data": data }; wixData.insert("books", toInsert) .then((results) => { let item = results; //see item below }) .catch((err) => { let errorMsg = err; }); }
If that doesn't answer your question please clarify the case.