Hi There,
I’m quite new to Wix and trying to sort point accrual system but I can’t move forward Really appreciate it if anyone can help me out.
Details as below
Registered members can earn points and it will be shown in another table called Bounty points, table’s Login Email column is linked via Reference field to Registered members so that whoever registered can get points.
But When it looped it gives email address Id instead of Login Email
Bounty Points table as below and reference field

Members details which linked to above bounty reference as below

LOOP as below
wixData.query("BountyPoints")
.find()
.then(function (va) {
for (let i = 0; i < va.items.length; i++) {
let bountiEmail = va.items[i].loginEmail;
let bountiPoints1 = va.items[i].bountyPoints1;
console.log(bountiEmail)
console.log(bountiPoints1)
}
});
Thanks in Advance
I believe that you need to include the reference field in your query. Something like this:
wixData.query("BountyPoints")
.include("loginEmail")
.find()
.then(function (va) {
... the rest of your code ...
Note: I haven’t tested this as I have not recreated your code and web site. However, you need to include the referenced field to get the contents (and not just the ID). See the include() API for details.
Hi @yisrael-wix Thanks so much for your answer. It’s working now, But popped up another issue,
I have a points table, users have earned it, later they can claim points. If the user wants to claim it, they have to login and start the claiming.
Once the user logged in his email address will use as a reference to find his earned points in the points table.
I have used for loop to get all data from the point table and then if statement to match login email with points table email. But it doesn’t work as it should.
Should I use .filter() instead of “for loop” for this? great help if you can guide me
Codes as below
// For full API documentation, including code examples, visit https://wix.to/94BuAAs
import wixStores from 'wix-stores';
import { getCurrentCart } from 'backend/aModule.jsw';
import wixUsers from 'wix-users';
import wixData from 'wix-data';
//get login email address
let user = wixUsers.currentUser;
let userEmail;
user.getEmail()
.then((email) => {
userEmail = email;
});
$w.onReady(async function() {
let results = await getCurrentCart();
results = results.totals.subtotal //Get points of cart
wixData.query("BountyPoints")//query bountyPoints tbl find login usr email&points
.include("loginEmail")
.find()
.then(function (va) {
for (let i = 0; i < va.items.length; i++) { //Looping table to get all the datas
let bountiEmail = va.items[i].loginEmail.loginEmail;
let bountiPoints1 = va.items[i].bountyPoints1;
if (bountiEmail === userEmail && bountiPoints1 < results) {
$w("#text48").show();
} else {
(bountiPoints >= results)
$w("#text48").hide();
}
}
});
})