Skip to main content
Solved

Can't get selectRecordsAsync() to work


Kim_Trager1
Forum|alt.badge.img+21

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

Best answer by kuovonne

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()
View original
Did this topic help you find an answer to your question?

6 replies

Forum|alt.badge.img+18
  • Inspiring
  • 254 replies
  • July 27, 2020

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)

kuovonne
Forum|alt.badge.img+27
  • Brainy
  • 6006 replies
  • Answer
  • July 27, 2020

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

Kim_Trager1
Forum|alt.badge.img+21
  • Author
  • Inspiring
  • 157 replies
  • July 27, 2020
kuovonne wrote:

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 :pray: . I don’t know why I did not realise that I need await the promise…


Kim_Trager1
Forum|alt.badge.img+21
  • Author
  • Inspiring
  • 157 replies
  • July 27, 2020
Zollie wrote:

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


Forum|alt.badge.img+18
  • Inspiring
  • 254 replies
  • July 27, 2020
Kim_Trager1 wrote:

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


kuovonne
Forum|alt.badge.img+27
  • Brainy
  • 6006 replies
  • July 27, 2020
Kim_Trager1 wrote:

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