Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

Can't get selectRecordsAsync() to work

Topic Labels: Scripting extentions
Solved
Jump to Solution
2818 6
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Accepted Solutions
kuovonne
18 - Pluto
18 - Pluto

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

See Solution in Thread

6 Replies 6
Zollie
10 - Mercury
10 - Mercury

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
18 - Pluto
18 - Pluto

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…

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

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.