I am trying to populate a textbox from backend code upon entering the page. The data returns properly when outputted to the console… I just cannot get the value to be set on the page from the code. Everything looks correct. What am I missing? Thank you!
import {getBusinessTotal} from 'backend/business
$w.onReady(async function () {
$w('#txt30').onViewportEnter(async () => {
$w('#txt30').text = getBusinessTotal();
});
});
import { sql } from '@velo/wix-data-sql-backend';
export async function getBusinessTotal(){
try{
let enddate = new Date().toISOString()
enddate = enddate.substring(0, 10)
let startdate = new Date()
let startdate2 = subtractDays(startdate,30)
let startdate3 = new Date(startdate2).toISOString()
let startdate4 = startdate3.substring(0, 10)
let mySQL = `SELECT sum(loanAmount) from Applications WHERE assigneeEmail = 'test@test.com' AND submitDate >= "${startdate4}"`
const results = await sql(mySQL);
let aResults = results.payload.data.rows;
if(aResults.length > 0)
return results.payload.data.rows[0].loanAmountSum
else
return 0
}
catch (error) {
return 0;
}
}