I am trying to retrieve the first and last name of a user and display it on a text element. I am doing this using the getCurrentItem() function and it was working fine, until it didn't anymore.
I have checked previous forum posts saying that it should be in the ready() function of the dataset, but it is and so I am not sure why this is not working. It is always pulling up the name of the first item from the collection, instead of the user who is currently logged in.
Here is my code:
$w.onReady( () => { $w("#dataset1").onReady( () => { let firstName= $w("#dataset1").getCurrentItem().title; let lastName= $w("#dataset1").getCurrentItem().lastName; $w("#text63").text = firstName + " " + lastName + " - Viewer" ; } ); });
Can anyone please tell me why is this not working?
Anyone know how to add the id? Please let me know
Current User is now a defunct method of getting data from a database. I had actually spent 12 hours the other day figuring it all out (partly because Promises were still a mystery to me). The new way to get this data is the get() function:
import wixData from 'wix-data'; // ... wixData.get("database", "elementid") .then( (results) => { let firstname = results.title; let lastname = results.lastName; //________________________________ $w("#text63").text=firstName+ " " +lastName+ " - Viewer" ; //Do all of your work with these variables here. //_________________________________ } ) .catch( (err) => { let errorMsg = err; } );
How does a visitor arrive at this page? To what collection is dataset1 connected? How is the current item set before arriving at this page?
You say that it was working before. What did it do? How was it used?