Can't get selectRecordsAsync() to work

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)
1 Like

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

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

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_Trager. Thanks for catching the core issue @kuovonne

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.

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.