So i have generated a public.js file
contents of said file
import wixData from ‘wix-data’;
export function problems (){
var routeproblems = “”;
wixData.query(“database”)
.ne(“Status”, “Running”)
.find()
.then( (results) => {
var i = 0 ;
do {
routeproblems = routeproblems + " " + results.Route[i];
i++;
}
while (i <= results.length);
});
return routeproblems;
}
So basically we have a database for bussing , If the status changes to anything but running i need to report it back to the site, So i wrote this in my new-file.js
on the dynamic page, i have
import {problems} from ‘public/new-file.js’ ;
export function table1_click(event, $w) {
//Add your code for this event here:
var pb = problems();
if (pb !== “”){
$w(“#text18”).html = “The Following Bussing routes have problems” + pb;
$w(“#text14”).collapse();
$w(“#text17”).expand();
}
if (pb === “”){
$w(“#text18”).html = “All Busses are running as scheduled”;
$w(“#text17”).collapse();
$w(“#text14”).expand();
}
}
Where text 17/14 are text that i have formatted to be something specific for if there is a problem or not, But when i click on the table. no matter what is set in my status table i get "All busses are running as scheduled.
Hi Travis,
I’ve made some changes in your code and added Async and Await declaration
export async function table1_click(event, $w) {
//Add your code for this event here:
var pb = await problems();
console.log('pb', typeof pb);
if (pb !== ""){
$w("#text18").html = "The Following Bussing routes have problems" + pb;
$w("#text14").collapse();
$w("#text17").expand();
}
if (pb === ""){
$w("#text18").html = "All Busses are running as scheduled";
$w("#text17").collapse();
$w("#text14").expand();
}
}
And:
export async function problems() {
let routeproblems = "";
let results = await wixData.query("StPaulBussing")
.ne("Status", "Running")
.find();
var items = results.items;
var i = 0;
do {
routeproblems = routeproblems + " " + items.Route[i];
i++;
}
while (i <= results.length);
return routeproblems;
}
Wow Thanks Roi, So Close it now generates a line of text that says this The Following Bussing routes have problems[object Promise] instead of The Following Bussing Routes have problems TH9 for example