Hi, I’m trying to get userId (and another stuff from Private Members Data) and copy it to my comment section DB. But it always shows error. Here’s my code
import wixUsers from ‘wix-users’;
import wixWindow from ‘wix-window’;
import wixData from ‘wix-data’;
$w.onReady( function () { // Disable the comment button until the page has loaded its dataset
$w(‘#SendComment’).disable();
$w(‘#dataset1’).onReady(() => {
// Get the item for use later
dynamicPageItem = $w(‘#dataset1’).getCurrentItem();
// Data set loaded so we can enable the comments button
$w(‘#SendComment’).enable();
});
});
export function SendComment_click(event) {
if (wixUsers.currentUser.loggedIn) {
console.log(wixUsers.currentUser.id);
if ($w(‘#Comment’).value.length > 0) {
let comment = $w(‘#Comment’).value;
let userId = wixUsers.currentUser.id;
wixData.query(“PrivateMembersData”)
.eq(“contactId”, userId)
.find()
.then((results) => {
let userCategory = results.items[0].category;
console.log(userCategory);
let CommentRecord = {
‘userId’: userId,
‘comment’: comment,
‘label’: userCategory
}
wixData.save(‘CommentSection’, CommentRecord)
.then((savedRecord) => {
console.log(savedRecord)
})
})
. catch ((error) => {
$w(‘#errtext’).text = “error”
console.log(error);
})
} else {
$w(‘#commentFail’).show();
console.log(“Type your Comment”)
}
} else {
wixWindow.openLightbox(“SignIn”)
}
}