I use a Web Module in the Backend with 2 functions and a variable.
I want to initialize the variable with one exported function and use it in the other function, both called from a Frontend page.
For some reason, I get null:
let item;
export function func1(objId) {
try{
return wixData.query("objects").eq("_id",objId)
.find()
.then(async (results) => {
if (results.items.length > 0){
item = results.items[0]; //init item
let reservationObj = item;
return reservationObj;
}else{
console.log("couldn't find object!!");
}
} );
} catch (err) {
console.log(err);
}
}
export function func2(){
return item._id === "some_id"; //at this point, item is null.
}
Any help?
Thanks!