Skip to main content

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')
}

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)


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()


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()

Thank you @kuovonne 🙏 . I don’t know why I did not realise that I need await the promise…


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)

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;)


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;)


You’re doing great @Kim_Trager1. Thanks for catching the core issue @kuovonne


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;)


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.


Reply