getItems results only visible inside function

// For full API documentation, including code examples, visit Velo API Reference - Wix.com
import {session} from ‘wix-storage’;
import wixData from ‘wix-data’;
var kw1,kw2,nm1,nm2;
$w.onReady( function () {
//TODO: write your page related code here…
let res = session.getItem(‘id’); //Where result will be a string
console.log(res);
$w(“#car”).setFilter( wixData.filter()
.eq(“typ”,res))

$w(“#car”).getItems(0, 1)
.then( (result) => {
let items = result.items;
kw1 =(items[0].chip3_kW-items[0].kW)/(items[0].kW/100);
nm1 =(items[0].chip3_nm-items[0].nm)/(items[0].nm/100);
console.log(kw1);
console.log(nm1);
let totalCount = result.totalCount;
let offset = result.offset;
} )
. catch ( (err) => {
let errMsg = err.message;
let errCode = err.code;
} );
//Add your code for this event here:
});

export function button1_click(event) {

$w(“#html1”).postMessage(“kw1”);
$w(“#html2”).postMessage(“nm1”);
}

kw1 and nm1 return undefined outside of the getItems function.
I need to use these values in my html component.

Did you try console.log() in the button1_click() function?

yes, I tried seeing which values are inside kw1 and nm1 outside of the getItems function and it returns as undefined. All I’m trying to do is store 2 values from the first row of the dataset in these variables and sending the to my html component

now it seems to work, i dont know what the problem was. Thanks for your time! I’ m still learning as you can see :slight_smile: