I have a profile page and I am trying to use a value in my “Associate” dataset and use it in creating a custom URL. I just need some help in actually getting the results. There will only ever be one Associate row returned. Thanks for your help.
Here is my pseudo-code:
Get The Associate Record that Matches The Logged On Users “ID”
Update the text field 19 and create a custom URL based on this format: http://www.testsite.com/
Here is the actual code:
import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(function () {
let r;
wixData.query("Associate")
.eq("ID",wixUsers.id)
.find()
.then( (results) => {
console.log(results.items);
r = results;
let itemObj = r.getCurrentItem();
} );
$w("#text19").html = "<a href='http://www.testsite.com/" + itemObj.username + "'>Your Site</a>";
});
That didn’t work. How can I see the results of the returned dataset in the console? Maybe there is a problem with the query. In my dataset “Associate” there is a field “Associate Add (ID)” which I assume is “ID” when using it in a query. It was autonamed by Wix so this must be correct.
In live Associate dataset, the value of the field for this user = /Associate/Add/d5832432-13b3-4c9d-bfd0-1bcee356ac21
How can I be sure that wixUsers.currentUser.id is returning the same value, therefore matching the ID in my dataset?
Is there a resource that shows me how to loop through the data? I am at a complete standstill. I need help. This should bring back one row, IF this piece of code is correct:
.eq("ID", wixUsers.currentUser.id)
In the database, it shows the ID being preceeded by “Associate/d5832432…” but when I output wixUsers.currentUser.id to the screen for debugging, it only shows “d5832432…” without the preceedeing “Associate/”. Is this my problem? I just don’t get it.
There is an id that is unique to each row in the database it is under the title “_id”. When you need to find a specific user, you need to find his id with wixUsers.currentUser.id and then in the database with query like this: