Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
async function not returning value

I am trying to return buildings and access it in the promise at the bottom of the script, but it seems like the console.log in the then part of the promise is executing before the getRecord function finishes, and so I can't access the array I am creating.

async function getRecords() {
     const buildings =[]
     data =updateTable.select({
        fields:['building_name']
    }).eachPage(function page(records, fetchNextPage){
        
        records.forEach(function(record){
            num++
            //console.log(num)
            try{
             //console.log(record['fields']['building_name'])
             
             buildings.push(record['fields']['building_name'])
            }
            catch(err){
                console.log('hello1')
                console.log(err)
            }

        }) 
            try{
        fetchNextPage()
            }
            
            catch{
                console.log('hello2')
                return buildings;
            }
    },function (err) {
        console.log(err)
        console.log('hello3')
        if (err) {
            console.log('errror')
            console.log(err);
            return;
        }
        console.log('hello4')
        console.log(buildings)
        console.log('hello5')
        return buildings
           
    });   console.log('hello6')
    }




getRecords().then(function(r){
    console.log('test')
    console.log(r)
})
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda