Jul 27, 2020 04:20 AM
I’ve been banging my head against the wall for a few hours, I can’t figure out why my selectRecordsAsync() does not pass anything into queryResult.
I think it has to do with me using an async function, but not sure why it wouldn’t work?
let poTable = 'PO/PI Paperwork'
let poView = 'test'
let btnPO = 'Client'
/////////FUNCTIONS
//Show PO list by client/////////
const poList = async () => {
let view = base.getTable(poTable).getView(poView);
let queryResult = await view.selectRecordsAsync();
return queryResult
}
///////////UI
if(btnPO === 'Client'){
console.log('Client')
let test = poList()
console.log(test)
}else if (btnPO ==='Number'){
console.log('Number')
}else if(btnPO === 'Yarn'){
console.log('Yarn')
}
Solved! Go to Solution.
Jul 27, 2020 07:38 AM
You’ve declared poList
to be an async function. In order to see the actual results, instead of the promise, you need to await the results.
let test = await poList()
Jul 27, 2020 06:50 AM
Try breaking it up into chunks and get those working first, then build on it. For example, the code below should run.
let poTable = 'PO/PI Paperwork'
let poView = 'test'
let view = base.getTable(poTable).getView(poView);
let queryResult = await view.selectRecordsAsync();
console.log(queryResult)
Jul 27, 2020 07:38 AM
You’ve declared poList
to be an async function. In order to see the actual results, instead of the promise, you need to await the results.
let test = await poList()
Jul 27, 2020 11:20 AM
Thank you @kuovonne :pray: . I don’t know why I did not realise that I need await the promise…
Jul 27, 2020 11:22 AM
As it’s part of a longer script I thought to put it all into functions, and wrap my head around the asynchronous functions… At the look at it I still have a bit to go;)
Jul 27, 2020 11:34 AM
You’re doing great @Kim_Trager1. Thanks for catching the core issue @kuovonne
Jul 27, 2020 11:45 AM
Putting things in functions can both simplify things and add complexity. I recommend creating only one function at a time and frequent testing to make debugging easier.