Please help. Can you please tell me what’s wrong with my code bellow. I have all time record not found : $w(‘#input3’).value = results.length all time is equal 0.
Thank you.
export function start_click(event) {
//Get current user email
getUserEmail();
//Check if the user already has a profile in the profiles database
searchForDuplicates();
}
export function getUserEmail() {
$w(‘#input1’).value = “”;
let currentUser = wixUsers.currentUser;
return currentUser.getEmail()
.then( (userEmail) => {
$w(‘#input1’).value = userEmail;
} )
. catch ((err) => {
return err;
} );
}
export function searchForDuplicates() {
//Add your code for this event here:
wixData.query(“myCollection”)
.eq(“LoginMail”, $w(‘#input1’).value)
.find()
.then( (results) => {
$w(‘#input4’).value = results.totalCount.valueOf();
$w(‘#input3’).value = results.length.valueOf();
if (results.length >= 1)
{
$w(‘#input2’).value = “found”;
}
else
{
$w(‘#input2’).value = “not-found”; //all time I have this response
}
})
. **catch** ( (error) => {
let errorMsg = error.message;
let code = error.code;
console.log("error " + code + ": " + errorMsg);
} );
}