update function only works with wixData, not dataset. I need to pass the value returned from the query to set the dataset value. The code below works when I hard code the value… but, does not work when I call to the query that holds the value I need.
export function button1_click(event, $w) {
let typeName = $w(‘#dropdown1’).value;
$w("#dataset2").onReady(() => {
let typeId;
console.log("dataset is onReady...");
console.log('typeName: ' + typeName);
$w("#dataset2").setFieldValues({
“UserId”: user.id,
“Type_Id”: “New Name” //This is the value I am trying to set from the query below. But it always returns undefined.
});
});
}
export function getTypeId(typeName) {
return wixData.query(“Type”)
.eq(‘name’, typeName)
.find() // Run the query
.then(results => {
let items = results.items;
let firstItem = items[0];
let typeID = firstItem[‘_id’];
console.log('results in getTypeId function: ' + typeID); //this prints out the value fine..
$w("#dataset2").setFieldValue("FK_Type_Id", typeID); //this will not set the value.
return items; // this returns undefined
}). **catch** (error => {
console.log(error);
});