Hi, I have a database with user submitted data. I want to add a backend code to add user email to the database. I already have some entries that I need to update if possible.
So basically, I require some backend code that will fetch email id by taking item._ownerid as input.
Incase this is not possible, I would at least like to add code in beforeInsert hook that would add the email id each time.
I have tried this code, but it doesn’t seem to be adding any entry.
import wixUsers from ‘wix-users-backend’;
export function User_Goals_beforeInsert(item, context) { let user=wixUsers.currentUser;
if (results.items.length > 0)
{
let details = results.items[0];
data.name=details.name;
data.email=details.loginEmail;
data.phone=details.mainPhone;
}
else
{
}
} )
. catch ( (err) => {
let errorMsg = err;
} );
However, you need to create a web module in the Backend section and write this code inside a function there. Because from front-end code won’t have permissions to access this database.
Also, if you don’t have that PrivateMembersData collection, you can easily add it by adding the E-commerce app to your site, and then deleting that E-commerce app if you don’t need it. I think that should work.
Cheers,
Sameer
I am not a skilled back-end coder and struggle a bit to implement the piece you suggested. Could I ask you to recommend me any tutorial on how to do that, or any helpful content (step-by-step, who to ask…)?
You can’t imagine how that would help me.
Thanks a lot for your time and attention,
All the best