Hi!,
After querying a database, and displaying the result (loginEmail) in a textbox (#text73), I can use it in an insert (//COMMENTLINE2). No problems with that. I paste the code below
But in case I would not save the loginEmail in the textbox, I could not find the way how to do the insert of that particular value. As it is in a variable (userEmail) (//COMMENTLINE1), I assumed I could use it in the Insert, but I couldn’t. I tried using let and var, thinking it was an scope issue… but got stuck . Looks like the moon to me.
Some help would be much appreciated
THE CODE
import wixUsers from ‘wix-users’ ;
import {session} from ‘wix-storage’ ;
import wixData from ‘wix-data’ ;
import wixLocation from ‘wix-location’ ;
$w.onReady( function () {
wixData.query( “Members/PrivateMembersData” )
.eq( “_id” , wixUsers.currentUser.id)
.find()
.then( (results) => {
let userEmail = results.items[ 0 ].loginEmail; //COMMENTLINE1
let userId = results.items[ 0 ]._id;
$w( “#text73” ).text = userEmail;
});
$w( "#repeater1" ).onItemReady(($w, dataItem, index) => {
let linkToDynamicPage = dataItem[ “link-clubbitnodo-1-title” ];
let linkToDynamicPage1 = dataItem[ “link-clubbitnodo-2-title” ];
$w( '#box72' ).onClick(() => {
//if (circuito === 1) {
$w( ‘#dataset1’ ).getCurrentItem();
let toInsert = {
“title” : $w( ‘#dataset1’ ).getCurrentItem().title,
“nombre” : $w( ‘#dataset1’ ).getCurrentItem().nombre,
“origen” : “1” ,
“circuito” : “1” ,
“userMail” : $w( ‘#text73’ ).text, // COMMENTLINE2
};
wixData.insert( "clubbitUsrccio" , toInsert)
.then( (results) => {
console.log( "done adding item" )
})
. **catch** ( (err) => {
let errorMsg = err;
});
});
});
});